diff --git a/mypy/util.py b/mypy/util.py index d3f49f74bbae..d7ff2a367fa2 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -66,7 +66,7 @@ def is_dunder(name: str, exclude_special: bool = False) -> bool: 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 1a07e4527527..1ab8109eda75 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -2524,3 +2524,18 @@ class Base: 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]