Skip to content

Commit 7282eb8

Browse files
committed
error wording
1 parent 4c4b78b commit 7282eb8

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ def analyze_name_lvalue(
42364236
)
42374237

42384238
if explicit_type and has_explicit_value:
4239-
self.fail("Type annotations are not allowed for enum members", lvalue)
4239+
self.fail("Enum members must be left unannotated", lvalue)
42404240

42414241
if (not existing or isinstance(existing.node, PlaceholderNode)) and not outer:
42424242
# Define new variable.

test-data/unit/check-enum.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ class B(A):
17641764
x = 1 # E: Cannot override writable attribute "x" with a final one
17651765

17661766
class A1(Enum):
1767-
x: int = 1 # E: Type annotations are not allowed for enum members
1767+
x: int = 1 # E: Enum members must be left unannotated
17681768
class B1(A1): # E: Cannot extend enum with existing members: "A1"
17691769
pass
17701770

@@ -2191,8 +2191,8 @@ def some_a(a: A):
21912191
from enum import Enum
21922192

21932193
class Medal(Enum):
2194-
gold: int = 1 # E: Type annotations are not allowed for enum members
2195-
silver: str = 2 # E: Type annotations are not allowed for enum members \
2194+
gold: int = 1 # E: Enum members must be left unannotated
2195+
silver: str = 2 # E: Enum members must be left unannotated \
21962196
# E: Incompatible types in assignment (expression has type "int", variable has type "str")
21972197
bronze = 3
21982198

@@ -2202,7 +2202,7 @@ from enum import Enum
22022202

22032203
class Pet(Enum):
22042204
CAT = ...
2205-
DOG: str = ... # E: Type annotations are not allowed for enum members \
2205+
DOG: str = ... # E: Enum members must be left unannotated \
22062206
# E: Incompatible types in assignment (expression has type "ellipsis", variable has type "str")
22072207

22082208
[file test.pyi]

test-data/unit/pythoneval.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,9 +1609,9 @@ reveal_type(Foo.Bar.value) # this should probably not be "Foo" https://typing.r
16091609
reveal_type(Foo.Baz)
16101610
reveal_type(Foo.Baz.value)
16111611
[out]
1612-
_testEnumValueWithPlaceholderNodeType.py:5: error: Type annotations are not allowed for enum members
1612+
_testEnumValueWithPlaceholderNodeType.py:5: error: Enum members must be left unannotated
16131613
_testEnumValueWithPlaceholderNodeType.py:5: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "Foo")
1614-
_testEnumValueWithPlaceholderNodeType.py:6: error: Type annotations are not allowed for enum members
1614+
_testEnumValueWithPlaceholderNodeType.py:6: error: Enum members must be left unannotated
16151615
_testEnumValueWithPlaceholderNodeType.py:6: error: Name "Missing" is not defined
16161616
_testEnumValueWithPlaceholderNodeType.py:8: note: Revealed type is "Literal[_testEnumValueWithPlaceholderNodeType.Foo.Bar]?"
16171617
_testEnumValueWithPlaceholderNodeType.py:9: note: Revealed type is "_testEnumValueWithPlaceholderNodeType.Foo"

0 commit comments

Comments
 (0)