8000 Single underscore is not a sunder by A5rocks · Pull Request #19273 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Single underscore is not a sunder #19273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Single underscore is not a sunder
    8000
  • Loading branch information
A5rocks committed Jun 11, 2025
commit 6ec79e744f9bcf1ab17e2057028e3ffaf16630cf
2 changes: 1 addition & 1 deletion mypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
0