@@ -56,7 +56,7 @@ class Truth(Enum):
5656x = ''
5757x = Truth.true.name
5858reveal_type(Truth.true.name) # N: Revealed type is "Literal['true']?"
59- reveal_type(Truth.false.value) # N: Revealed type is "builtins.bool "
59+ reveal_type(Truth.false.value) # N: Revealed type is "Literal[False]? "
6060[builtins fixtures/bool.pyi]
6161
6262[case testEnumValueExtended]
@@ -66,7 +66,7 @@ class Truth(Enum):
6666 false = False
6767
6868def infer_truth(truth: Truth) -> None:
69- reveal_type(truth.value) # N: Revealed type is "builtins.bool "
69+ reveal_type(truth.value) # N: Revealed type is "Union[Literal[True]?, Literal[False]?] "
7070[builtins fixtures/bool.pyi]
7171
7272[case testEnumValueAllAuto]
@@ -90,7 +90,7 @@ def infer_truth(truth: Truth) -> None:
9090[builtins fixtures/primitives.pyi]
9191
9292[case testEnumValueExtraMethods]
93- from enum import Enum, auto
93+ from enum import Enum
9494class Truth(Enum):
9595 true = True
9696 false = False
@@ -99,7 +99,7 @@ class Truth(Enum):
9999 return 'bar'
100100
101101def infer_truth(truth: Truth) -> None:
102- reveal_type(truth.value) # N: Revealed type is "builtins.bool "
102+ reveal_type(truth.value) # N: Revealed type is "Union[Literal[True]?, Literal[False]?] "
103103[builtins fixtures/bool.pyi]
104104
105105[case testEnumValueCustomAuto]
@@ -129,6 +129,20 @@ def cannot_infer_truth(truth: Truth) -> None:
129129 reveal_type(truth.value) # N: Revealed type is "Any"
130130[builtins fixtures/bool.pyi]
131131
132+ [case testEnumValueSameType]
133+ from enum import Enum
134+
135+ def newbool() -> bool:
136+ ...
137+
138+ class Truth(Enum):
139+ true = newbool()
140+ false = newbool()
141+
142+ def infer_truth(truth: Truth) -> None:
143+ reveal_type(truth.value) # N: Revealed type is "builtins.bool"
144+ [builtins fixtures/bool.pyi]
145+
132146[case testEnumUnique]
133147import enum
134148@enum.unique
@@ -1362,6 +1376,25 @@ class E(IntEnum):
13621376reveal_type(E.A.value) # N: Revealed type is "__main__.N"
13631377
13641378
1379+ [case testEnumFinalValues]
1380+ from enum import Enum
1381+ class Medal(Enum):
1382+ gold = 1
1383+ silver = 2
1384+
1385+ # Another value:
1386+ Medal.gold = 0 # E: Cannot assign to final attribute "gold"
1387+ # Same value:
1388+ Medal.silver = 2 # E: Cannot assign to final attribute "silver"
1389+
1390+
1391+ [case testEnumFinalValuesCannotRedefineValueProp]
1392+ from enum import Enum
1393+ class Types(Enum):
1394+ key = 0
1395+ value = 1 # E: Cannot override writable attribute "value" with a final one
1396+
1397+
13651398[case testEnumReusedKeys]
13661399# https://github.com/python/mypy/issues/11248
13671400from enum import Enum
@@ -1405,13 +1438,13 @@ class NonEmptyIntFlag(IntFlag):
14051438 x = 1
14061439
14071440class ErrorEnumWithValue(NonEmptyEnum): # E: Cannot inherit from final class "NonEmptyEnum"
1408- x = 1
1441+ x = 1 # E: Cannot override final attribute "x" (previously declared in base class "NonEmptyEnum")
14091442class ErrorIntEnumWithValue(NonEmptyIntEnum): # E: Cannot inherit from final class "NonEmptyIntEnum"
1410- x = 1
1443+ x = 1 # E: Cannot override final attribute "x" (previously declared in base class "NonEmptyIntEnum")
14111444class ErrorFlagWithValue(NonEmptyFlag): # E: Cannot inherit from final class "NonEmptyFlag"
1412- x = 1
1445+ x = 1 # E: Cannot override final attribute "x" (previously declared in base class "NonEmptyFlag")
14131446class ErrorIntFlagWithValue(NonEmptyIntFlag): # E: Cannot inherit from final class "NonEmptyIntFlag"
1414- x = 1
1447+ x = 1 # E: Cannot override final attribute "x" (previously declared in base class "NonEmptyIntFlag")
14151448
14161449class ErrorEnumWithoutValue(NonEmptyEnum): # E: Cannot inherit from final class "NonEmptyEnum"
14171450 pass
0 commit comments