You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think there's any problems making it covariant, because I would assume it will be replaced by TypeVarTuple (PEP 646), and tuples are covariant. In the interim, there's a few functions that change the shape of the array, such as __getitem__, but it seems those return ndarray[Any,] except in the overload:
I'm not sure what situation this is handling, since I've never seen self typed.
There's also the chararray, memmap, matrix, recordarray, MaskedArray, and MaskedRecord types (of which the latter two define an identical _ShapeType type variable), but their methods also appear to return Any as the shape of any return that isn't the same shape.
Would you mind if I PR'd this and saw if it passes type checking?
The text was updated successfully, but these errors were encountered:
Jacob-Stevens-Haas
changed the title
ENH: _ShapeType should be covariant
ENH: Should _ShapeType be covariant?
Jan 30, 2024
Fixesnumpy#25729
This change allows future changes to the static typing of numpy that modify
or only work with certain numbers of dimensions. It also applies the change
to subclasses of ndarray and adds tests. It allows users to statically
type their array shapes with subtypes of tuple (e.g. NamedTuple) and tuples
of int subtypes (e.g. Literal or NewType).
For a discussion of the merits of TypeVarTuple vs a tuple-bound TypeVar, see
the linked PR
Proposed new feature or change:
I believe
_ShapeType
should be covariant. For instance, the following code does not typecheck because_ShapeType
is invariant:I don't think there's any problems making it covariant, because I would assume it will be replaced by
TypeVarTuple
(PEP 646), and tuples are covariant. In the interim, there's a few functions that change the shape of the array, such as__getitem__
, but it seems those returnndarray[Any,]
except in the overload:I'm not sure what situation this is handling, since I've never seen
self
typed.There's also the
chararray
,memmap
,matrix
,recordarray
,MaskedArray
, andMaskedRecord
types (of which the latter two define an identical_ShapeType
type variable), but their methods also appear to returnAny
as the shape of any return that isn't the same shape.Would you mind if I PR'd this and saw if it passes type checking?
The text was updated successfully, but these errors were encountered: