- Notifications
You must be signed in to change notification settings - Fork3.8k
Added Rect typing and docs that it is iterable#2969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
Starbuck5 commentedJan 3, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Typing might want to be something like this instead:https://stackoverflow.com/questions/49427944/typehints-for-sized-iterable-in-python MightyJosip or Ankith would have a better idea of this than I do. |
ankith26 left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
WhileRect is indeed iterable, the C code does not actually implement the__iter__ method as quickly demonstrated by this example.
>>> a = pygame.Rect(0, 0, 0, 0)>>> a.__iter__()Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'pygame.Rect' object has no attribute '__iter__'. Did you mean: '__str__'?However, it does implement a subset of theSequence protocol, including a__len__ method, which does need typehints here. AnIterable would implement an__iter__ method, but aSequence only needs__getitem__ and python puts a mixin for__iter__ that uses this under the hood. Perhaps theRect typestub class should inherit from theSequence ABC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🎉 👍
So I did more digging, and posting some notes of my findings here
We can still merge this PR because adding |
I took this "We can still merge this PR" as an approval :) Thankses. |
Fix:#2681