Skip to content

(🐞) Enum.name is Any in 3.11 #7564

Closed
python/mypy
#14133

Description

@KotlinIsland
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,

Activity

  1. JelleZijlstra commented on Mar 29, 2022

    @JelleZijlstra
    Member

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

  2. KotlinIsland commented on Mar 29, 2022

    @KotlinIsland
    ContributorAuthor

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

  3. JelleZijlstra commented on Mar 29, 2022

    @JelleZijlstra
    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.

  4. KotlinIsland commented on Mar 29, 2022

    @KotlinIsland
    ContributorAuthor

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

  5. JelleZijlstra commented on Mar 29, 2022

    @JelleZijlstra
    Member
  6. KotlinIsland commented on Mar 29, 2022

    @KotlinIsland
    ContributorAuthor

    I had my 3.10 venv active 😳

  7. AlexWaygood commented on Mar 29, 2022

    @AlexWaygood
    Member

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions