Fix __class_getitem__ to be positional-only#3410
Conversation
|
I've looked around and failed to find information about key parameter being required a positional-only: Edit: |
aatle
left a comment
There was a problem hiding this comment.
If you would like, you can rename generic to item to be consistent with typeshed.
LGTM;
Update sprite.pyi
ac8c795 to
e76176b
Compare
|
I updated the code to use I also want to keep code changes out of this stubs PR so I am not changing the parent classes in the implementation, though someone could take it up in the future if interested. |
|
I played around a bit with list's implementation, it being positional only seems to be standard. >>> list.__class_getitem__(key=int)
Traceback (most recent call last):
File "<python-input-9>", line 1, in <module>
list.__class_getitem__(key=int)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: list.__class_getitem__() takes no keyword argumentsAlso ofc class getitem is meant to be used by type hints, and trying to use a keyword there is a syntax error. >>> list[key=int]
File "<python-input-5>", line 1
list[key=int]
^^^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='? |
As noted by @aatle in #3398,
__class_getitem__is positional only, and stubtest on python 3.13 complains about this issue. This PR fixes that.