Skip to content

[stubtest] Improve checking of positional-only parameters in dunder methods #19593

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def do_func_def(

lineno = n.lineno
args = self.transform_args(n.args, lineno, no_type_check=no_type_check)
if special_function_elide_names(n.name):
if self.options.pos_only_special_methods and special_function_elide_names(n.name):
for arg in args:
arg.pos_only = True

Expand Down
3 changes: 3 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ def __init__(self) -> None:
# Export line-level, limited, fine-grained dependency information in cache data
# (undocumented feature).
self.export_ref_info = False
# Treat special methods as being implicitly positional-only.
# Set to False when running stubtest.
self.pos_only_special_methods = True

self.disable_bytearray_promotion = False
self.disable_memoryview_promotion = False
Expand Down
2 changes: 1 addition & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,6 @@ def _verify_signature(
and not stub_arg.pos_only
and not stub_arg.variable.name.startswith("__")
and stub_arg.variable.name.strip("_") != "self"
and not is_dunder(function_name, exclude_special=True) # noisy for dunder methods
):
yield (
f'stub argument "{stub_arg.variable.name}" should be positional-only '
Expand Down Expand Up @@ -2010,6 +2009,7 @@ def test_stubs(args: _Arguments, use_builtins_fixtures: bool = False) -> int:
options.use_builtins_fixtures = use_builtins_fixtures
options.show_traceback = args.show_traceback
options.pdb = args.pdb
options.pos_only_special_methods = False

if options.config_file:

Expand Down
Loading