Skip to content

Commit e253ede

Browse files
A5rocksJukkaL
authored andcommitted
Single underscore is not a sunder (#19273)
Fixes #19271.
1 parent 9fb5ff6 commit e253ede

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mypy/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def is_dunder(name: str, exclude_special: bool = False) -> bool:
6666

6767

6868
def is_sunder(name: str) -> bool:
69-
return not is_dunder(name) and name.startswith("_") and name.endswith("_")
69+
return not is_dunder(name) and name.startswith("_") and name.endswith("_") and name != "_"
7070

7171

7272
def split_module_names(mod_name: str) -> list[str]:

test-data/unit/check-enum.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,3 +2524,18 @@ class Base:
25242524
self.o = Enum("o", names) # E: Enum type as attribute is not supported \
25252525
# E: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members
25262526
[builtins fixtures/tuple.pyi]
2527+
2528+
[case testSingleUnderscoreNameEnumMember]
2529+
# flags: --warn-unreachable
2530+
2531+
# https://github.com/python/mypy/issues/19271
2532+
from enum import Enum
2533+
2534+
class Things(Enum):
2535+
_ = "under score"
2536+
2537+
def check(thing: Things) -> None:
2538+
if thing is Things._:
2539+
return None
2540+
return None # E: Statement is unreachable
2541+
[builtins fixtures/enum.pyi]

0 commit comments

Comments
 (0)