Closed
Description
I'd like to define a protocol that extends the numpy N-D Array. I can't create an abstract base class for unrelated reasons. I'd like to do something like the following:
from typing import Protocol
import numpy.typing import NDArrayProtocol # Currently doesn't exist
class NdArrayWithMethod(NDArrayProtocol, Protocol):
def method(self, input) -> None: pass
class ImpementsProtocol(np.ndarray):
def method(self, input):
...
class AlsoImpementsProtocol(np.ndarray):
def method(self, input):
...
def operates on protocol(in: NdArrayWithMethod):
...
The protocol cannot subclass ndarray
directly, so I need to use something like NDArrayProtocol
. Is there an ndarray protocol exposed somewhere?