Skip to content

Commit 8b9f205

Browse files
JelleZijlstrailevkivskyi
authored andcommitted
names that end with __ are not positional-only (#5158)
Also removed a duplicate test case (apparently a holdover from before fastparse).
1 parent c78f6ea commit 8b9f205

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

mypy/sharedparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ def special_function_elide_names(name: str) -> bool:
104104

105105

106106
def argument_elide_name(name: Optional[str]) -> bool:
107-
return name is not None and name.startswith("__")
107+
return name is not None and name.startswith("__") and not name.endswith("__")

test-data/unit/check-functions.test

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,25 +2073,18 @@ h(7) # E: Cannot call function of unknown type
20732073

20742074
[case testPositionalOnlyArg]
20752075
def f(__a: int) -> None: pass
2076+
def g(__a__: int) -> None: pass
20762077

20772078
f(1)
20782079
f(__a=1) # E: Unexpected keyword argument "__a" for "f"
20792080

2080-
[builtins fixtures/bool.pyi]
2081-
[out]
2082-
main:1: note: "f" defined here
2083-
2084-
[case testPositionalOnlyArgFastparse]
2085-
2086-
2087-
def f(__a: int) -> None: pass
2088-
2089-
f(1)
2090-
f(__a=1) # E: Unexpected keyword argument "__a" for "f"
2081+
g(1)
2082+
# Argument names that also end with __ are not positional-only.
2083+
g(__a__=1)
20912084

20922085
[builtins fixtures/bool.pyi]
20932086
[out]
2094-
main:3: note: "f" defined here
2087+
main:1: note: "f" defined here
20952088

20962089
[case testMagicMethodPositionalOnlyArg]
20972090
class A(object):

0 commit comments

Comments
 (0)