-
Notifications
You must be signed in to change notification settings - Fork 765
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
Enum issue #6381
Comments
This behavior is intended. Instances of of I'm guessing that this was recently changed in the typeshed stubs, which would explain why you didn't see this error in older versions of pylance. |
Actually, it looks like a name is synthesized at runtime for combinations. x: Test = Test.Two | Test.Four
print(x.name.lower()) # prints "two|four" So this might be a bug in the typeshed stubs. If you'd like to pursue that, you can file a bug report or PR in the typeshed proejct. All of the major type checkers (including pyright, which pylance is built upon) make use of these stubs. |
The same issue on Id attribute of Django models. Also on ManyToMany, ForeignKey fields |
Trusting: https://github.com/python/cpython/blob/cbfeb6a7fe89101e24ba7f61b5d42e12b79f1c9d/Lib/enum.py#L1492, it is possible for a FlagInt to have name
Seems that Pylance is doing this thing correctly, or I'm being mistaken here. Changed Thank you, Erictraut, for pushing me in the right direction.
Luanft, indeed I have the same issue happening, but shouldn't it be a different 'bug'? |
going to close it as by design. for the other issue, please open new issue |
Environment data
Code Snippet
Expected behavior
I excepected
.name
to always return a string, especially since all Enum's class members are hard-coded.Actual behavior
As you can see, it claims, whatever is returned cannot get the
.lower()
treatment, because it might be a None.The text was updated successfully, but these errors were encountered: