Skip to content

Allow enum members to have type objects as values #19160

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

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3301,8 +3301,8 @@ def enum_members(self) -> list[str]:
continue # unannotated value not a member

typ = mypy.types.get_proper_type(sym.node.type)
if isinstance(
typ, mypy.types.FunctionLike
if (
isinstance(typ, mypy.types.FunctionLike) and not typ.is_type_obj()
) or ( # explicit `@member` is required
isinstance(typ, mypy.types.Instance)
and typ.type.fullname == "enum.nonmember"
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -2638,3 +2638,24 @@ def f2() -> None:
return
reveal_type(y) # N: Revealed type is "builtins.str"
[builtins fixtures/list.pyi]

[case testEnumTypeObjectMember]
import enum
from typing import NoReturn

def assert_never(x: NoReturn) -> None: ...

class ValueType(enum.Enum):
INT = int
STR = str

value_type: ValueType = ValueType.INT

match value_type:
case ValueType.INT:
pass
case ValueType.STR:
pass
case _:
assert_never(value_type)
[builtins fixtures/tuple.pyi]