Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
hauntsaninja merged 16 commits intopython:masterfromDaverball:fix-enum-truthyness
Nov 14, 2024

Conversation

@Daverball
Copy link
Contributor

@DaverballDaverball commentedJun 6, 2024
edited
Loading

Fixes:#17333

This ensurescan_be_true andcan_be_false on enum literals depends on the specificEnum fallback type behind theLiteral, since__bool__ can be overriden like on any other type.

Additionally typeopstrue_only andfalse_only now respect the metaclass when looking up the return values of__bool__ and__len__, which ensures that a defaultEnum that doesn't override__bool__ is still considered always truthy.

@github-actions

This comment has been minimized.

@Daverball

This comment was marked as resolved.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Daverball
Copy link
ContributorAuthor

BTW I found it a little concerning thatTypeInfo.get andTypeInfo.get_method only consider the mro and not the metaclass when looking up symbols, but I didn't have the stomach to change this, since there probably is code that depends on this behavior.

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 ofget/clean this up/improve documentation to avoid more errors in the future?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Daverball
Copy link
ContributorAuthor

@hauntsaninja Not asking for a review (although that would be nice too), but for your thoughts on my comment above:#17337 (comment)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninjahauntsaninja left a 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

Daverball reacted with thumbs up emoji
@hauntsaninjahauntsaninja merged commitfa01a07 intopython:masterNov 14, 2024
19 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@hauntsaninjahauntsaninjahauntsaninja approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Truthyness inference incorrect for someEnum types

2 participants

@Daverball@hauntsaninja

[8]ページ先頭

©2009-2025 Movatter.jp