Skip to content

Commit 7ce3b9e

Browse files
committed
[stubtest] Improve checking of pos-only args in dunder methods
1 parent 64dff42 commit 7ce3b9e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

mypy/fastparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def do_func_def(
929929

930930
lineno = n.lineno
931931
args = self.transform_args(n.args, lineno, no_type_check=no_type_check)
932-
if special_function_elide_names(n.name):
932+
if self.options.pos_only_special_methods and special_function_elide_names(n.name):
933933
for arg in args:
934934
arg.pos_only = True
935935

mypy/options.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ def __init__(self) -> None:
398398
# Export line-level, limited, fine-grained dependency information in cache data
399399
# (undocumented feature).
400400
self.export_ref_info = False
401+
# Treat special methods as being implicitly positional-only.
402+
# Set to False when running stubtest.
403+
self.pos_only_special_methods = True
401404

402405
self.disable_bytearray_promotion = False
403406
self.disable_memoryview_promotion = False

mypy/stubtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,6 @@ def _verify_signature(
943943
and not stub_arg.pos_only
944944
and not stub_arg.variable.name.startswith("__")
945945
and stub_arg.variable.name.strip("_") != "self"
946-
and not is_dunder(function_name, exclude_special=True) # noisy for dunder methods
947946
):
948947
yield (
949948
f'stub argument "{stub_arg.variable.name}" should be positional-only '
@@ -2010,6 +2009,7 @@ def test_stubs(args: _Arguments, use_builtins_fixtures: bool = False) -> int:
20102009
options.use_builtins_fixtures = use_builtins_fixtures
20112010
options.show_traceback = args.show_traceback
20122011
options.pdb = args.pdb
2012+
options.pos_only_special_methods = False
20132013

20142014
if options.config_file:
20152015

0 commit comments

Comments
 (0)