Single underscore is not a sunder (#19273) Fixes https://github.com/python/mypy/issues/19271.
diff --git a/mypy/util.py b/mypy/util.py index d3f49f7..d7ff2a3 100644 --- a/mypy/util.py +++ b/mypy/util.py
@@ -66,7 +66,7 @@ def is_sunder(name: str) -> bool: - return not is_dunder(name) and name.startswith("_") and name.endswith("_") + return not is_dunder(name) and name.startswith("_") and name.endswith("_") and name != "_" def split_module_names(mod_name: str) -> list[str]:
diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index cc9048d..3001bc9 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test
@@ -2524,3 +2524,18 @@ self.o = Enum("o", names) # E: Enum type as attribute is not supported \ # E: Second argument of Enum() must be string, tuple, list or dict literal for mypy to determine Enum members [builtins fixtures/tuple.pyi] + +[case testSingleUnderscoreNameEnumMember] +# flags: --warn-unreachable + +# https://github.com/python/mypy/issues/19271 +from enum import Enum + +class Things(Enum): + _ = "under score" + +def check(thing: Things) -> None: + if thing is Things._: + return None + return None # E: Statement is unreachable +[builtins fixtures/enum.pyi]