Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

(馃悶) Enum.name is Any in 3.11 #7564

Closed
KotlinIsland opened this issue Mar 29, 2022 · 7 comments 路 Fixed by python/mypy#14133
Closed

(馃悶) Enum.name is Any in 3.11 #7564

KotlinIsland opened this issue Mar 29, 2022 · 7 comments 路 Fixed by python/mypy#14133

Comments

@KotlinIsland
Copy link
Contributor

from enum import Enum

value: Enum

reveal_type(value)
reveal_type(value.name)
> mypy --python-version 3.10 test.py
test.py:5: note: Revealed type is "enum.Enum"
test.py:6: note: Revealed type is "str"
Success: no issues found in 1 source file

> mypy --python-version 3.11 test.py
test.py:5: note: Revealed type is "enum.Enum"
test.py:6: note: Revealed type is "Any"

Not 100% sure if this is a mypy issue or a typeshed issue,

@JelleZijlstra
Copy link
Member

I guess mypy doesn't understand the _magic_enum_attr here: https://github.com/python/typeshed/blob/master/stdlib/enum.pyi#L144

@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Mar 29, 2022

Is that intrinsic and needs to be special cased, or should it be handled by default?

@JelleZijlstra
Copy link
Member

It's an alias for property in the stubs. So on 3.11 we are using a subclass of property (from mypy's perspective), but on 3.10 and lower we are just using an alias. I guess the subclass is what's causing trouble.

@KotlinIsland
Copy link
Contributor Author

Thanks, I'll raise it with mypy, should we close this?

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Mar 29, 2022

It does on main, maybe you have an old 3.11 checkout.

https://github.com/python/cpython/blob/788154919c2d843a0a995994bf2aed2d074761ec/Lib/enum.py#L150

@KotlinIsland
Copy link
Contributor Author

I had my 3.10 venv active 馃槼

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 29, 2022

For Enum.name specifically, we can probably just pretend that it still uses types.DynamicClassAttribute in 3.11, as it does in <=3.10. It doesn't make much difference in the stubs, especially when mypy doesn't really support the intricacies of either types.DynamicClassAttribute or enum.property.

Sound good?

eli-schwartz added a commit to eli-schwartz/meson that referenced this issue Nov 4, 2022
mypy has a bug when running on/for 3.11 which results in incorrect
analysis of the codebase, specifically due to enum.Enum's self.name

See:

python/typeshed#7564
python/mypy#12483
eli-schwartz added a commit to eli-schwartz/meson that referenced this issue Nov 6, 2022
mypy has a bug when running on/for 3.11 which results in incorrect
analysis of the codebase, specifically due to enum.Enum's self.name

See:

python/typeshed#7564
python/mypy#12483
nirbheek pushed a commit to mesonbuild/meson that referenced this issue Nov 21, 2022
mypy has a bug when running on/for 3.11 which results in incorrect
analysis of the codebase, specifically due to enum.Enum's self.name

See:

python/typeshed#7564
python/mypy#12483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants