Skip to content

auto for StrEnum is incorrectly subclassing IntFlag #10384

Description

@DanielNoord
fromenumimportStrEnum, autofromtypingimportreveal_typeclassTest(StrEnum):
test=auto()
print(type(Test.test.value))
deffunc(x: Test):
print(reveal_type(x.value))
func(Test.test)

On 3.11 this returns:

python test.py<class 'str'>Runtime type is 'str'test

However, both pyright and mypy reveal the type as being int because of:

typeshed/stdlib/enum.pyi

Lines 289 to 290 in 201940c

# subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto()
classauto(IntFlag):

This was introduced all the way back in #1331.

Well it might be "mostly" correct, with StrEnum this is clearly false and leads to cases where we couldn't use StrEnum without adding type: ignores anyway.
I don't really know what the appropriate fix is so I sadly can't contribute one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    reason: inexpressibleClosed, because this can't be expressed within the current type system

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions