Should non-generic classes with `__class_getitem__` be subscriptable in a type expression?
Discussions on Python.org
Should non-generic classes with `__class_getitem__` be subscriptable in a type expression?
The AstroPy library documents a suggested pattern to type-annotate using an expression like Quantity[u.km]. Quantity is not a generic class, but it implements __class_getitem__ to return Annotated[Quantity, u.km] – effectively a shorthand for an Annotated annotation. AstroPy itself does not type-annotate the return value of Quantity.__class_getitem__ and doesn’t seem to publish type stubs, but recently a someone inquired about how to write type stubs for this pattern that will work in ty. ty r...
0 comments
No comments yet.