-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Understand the self-destructing nature of Enum._ignore_ #12128
Conversation
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.
Thank you!
Blocking
- Let's add a constant
Non-blocking
I think if we are adding _ignore_
support, we must be sure that this case works correctly:
class Some(Enum):
a = 1
b = 2
_ignore_ = ('a',)
reveal_type(Some.a)
reveal_type(Some.b)
However, I think that it can be addressed in a separate PR.
But, we need at least an new issue for it.
This comment has been minimized.
This comment has been minimized.
Created issue #12157. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Thank you!
Thank you too!
…On Fri, Feb 11, 2022 at 01:31 Nikita Sobolev ***@***.***> wrote:
***@***.**** approved this pull request.
Thank you!
—
Reply to this email directly, view it on GitHub
<#12128 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLDC2XQARTD2IYL5XB7PMTU2SUNHANCNFSM5NS7LXFQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
Looks good, thank you for this!
Similar to _order_ (which mypy already handles), _ignore_ is deleted by EnumMeta. Currently, (#12121) mypy thinks it's an error to set _ignore_ in an Enum subclass because 'Cannot override writable attribute "_ignore_" with a final one.' This PR both:
_ignore_
in the class body; and_ignore_
attribute ('Type[E] has no attribute "_ignore_"')The PR adds a test that accessing
_ignore_
after the class definition is flagged as an error. I wanted to test that (1) above has been fixed, but I couldn't figure out how to make a failing test. So I went "out of band" from the unit test themselves; I created a simple test file:And checked that before this PR, mypy raised an error on line 3 but not line 4, and after this PR line 3 was ok but line 4 was now in error.
This PR does not cause mypy itself to ignore the attributes. That is, after this definition:
mypy still thinks E.X exists. I suppose mypy could parse the value of
_ignore_
when it's a literal , but I don't have plans to look into that.