Closed eric-czech closed 4 years ago
This was a to-do I had in my xarray/scikit-allele prototype that I'll record the answer to here for posterity.
The question is what do signatures look like for functions operating on any array type implementing the __array_function__ protocol? E.g.:
__array_function__
def mean(arr: ?) -> number: return arr.sum()
The answer is structural subtyping via PEP-0544 (Protocols). This is out now at least in Python 3.8.2: https://docs.python.org/3/library/typing.html#nominal-vs-structural-subtyping
This was a to-do I had in my xarray/scikit-allele prototype that I'll record the answer to here for posterity.
The question is what do signatures look like for functions operating on any array type implementing the
__array_function__
protocol? E.g.:The answer is structural subtyping via PEP-0544 (Protocols). This is out now at least in Python 3.8.2: https://docs.python.org/3/library/typing.html#nominal-vs-structural-subtyping