(🐞) `Enum.name` is `Any` in 3.11
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,
I guess mypy doesn't understand the _magic_enum_attr here: https://github.com/python/typeshed/blob/master/stdlib/enum.pyi#L144
Is that intrinsic and needs to be special cased, or should it be handled by default?
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.
Thanks, I'll raise it with mypy, should we close this?
It does on main, maybe you have an old 3.11 checkout.
https://github.com/python/cpython/blob/788154919c2d843a0a995994bf2aed2d074761ec/Lib/enum.py#L150
I had my 3.10 venv active 😳
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?