Skip to content

Quantity.__class_getitem__ cannot use super on ndarray.__class_getitem__ on python >=3.10 #12510

@mhvk

Description

@mhvk

All PRs are currently failing their python 3.10 + devdeps tests because the interaction between Quantity.__class_getitem__ and ndarray.__class_getitem__ is not correct. E.g.,

In [2]: u.Quantity[u.m]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-f0c088963c1a> in <module>
----> 1 u.Quantity[u.m]

~/data/mhvk/packages/astropy/astropy/units/quantity.py in __class_getitem__(cls, unit_shape_dtype)
    404         # metadata using Annotated.
    405         if not NUMPY_LT_1_22:
--> 406             cls = super().__class_getitem__((cls, *shape_dtype))
    407         return Annotated.__class_getitem__((cls, unit))
    408 

TypeError: Too few arguments for Quantity

It seems that ndarray.__class_getitem__ cannot be called without an actual (shape, dtype). Those also should be meaningful, meaning that the current test u.Quantity[u.m, "more"] would seem to incorrectly associate this "more" with the ndarray aspect.

In [13]: u.Quantity[u.m, "more"]
Out[13]: typing.Annotated[astropy.units.quantity.Quantity[astropy.units.quantity.Quantity, 'more'], Unit("m")]

My sense is to remove the super() call... @nstarman??

Metadata

Metadata

Assignees

Labels

BugClose?Tell stale bot that this issue/PR is staleclosed-by-botClosed by stale botunits

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions