Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Fix incorrect truthyness for Enum types and literals#17337
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Daverball commentedJun 18, 2024
BTW I found it a little concerning that I fear however that there are quite a few more places where attribute lookups are incorrect (other than the one I have fixed in this PR), because the attribute is defined on the metaclass and not on the class itself. Should we perhaps create an issue to potentially review call sites of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Daverball commentedAug 2, 2024
@hauntsaninja Not asking for a review (although that would be nice too), but for your thoughts on my comment above:#17337 (comment) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
hauntsaninja left a comment
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.
Nice, thank you!
Re your comment: I think most attribute lookups should go throughanalyze_member_access
fa01a07 intopython:masterUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fixes:#17333
This ensures
can_be_trueandcan_be_falseon enum literals depends on the specificEnumfallback type behind theLiteral, since__bool__can be overriden like on any other type.Additionally typeops
true_onlyandfalse_onlynow respect the metaclass when looking up the return values of__bool__and__len__, which ensures that a defaultEnumthat doesn't override__bool__is still considered always truthy.