Skip to content

Commit 35a15b1

Browse files
stubtest: correct "argument" → "parameter" terminology in error messages (#19707)
## Description This PR fixes the incorrect usage of the word **"argument"** in `stubtest` error messages and replaces it with the correct term **"parameter"**, as requested in issue #16508. According to convention: - **Parameter** → part of the function signature - **Argument** → actual value passed when calling the function Since `stubtest` deals only with *parameters*, this correction improves the accuracy of the error messages. ## Related Issue Fixes #16508
1 parent 13fa6c3 commit 35a15b1

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

mypy/stubtest.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ def names_approx_match(a: str, b: str) -> bool:
747747
if stub_arg.variable.name == "_self":
748748
return
749749
yield (
750-
f'stub argument "{stub_arg.variable.name}" '
751-
f'differs from runtime argument "{runtime_arg.name}"'
750+
f'stub parameter "{stub_arg.variable.name}" '
751+
f'differs from runtime parameter "{runtime_arg.name}"'
752752
)
753753

754754

@@ -759,8 +759,8 @@ def _verify_arg_default_value(
759759
if runtime_arg.default is not inspect.Parameter.empty:
760760
if stub_arg.kind.is_required():
761761
yield (
762-
f'runtime argument "{runtime_arg.name}" '
763-
"has a default value but stub argument does not"
762+
f'runtime parameter "{runtime_arg.name}" '
763+
"has a default value but stub parameter does not"
764764
)
765765
else:
766766
runtime_type = get_mypy_type_of_runtime_value(runtime_arg.default)
@@ -781,9 +781,9 @@ def _verify_arg_default_value(
781781
and not is_subtype_helper(runtime_type, stub_type)
782782
):
783783
yield (
784-
f'runtime argument "{runtime_arg.name}" '
784+
f'runtime parameter "{runtime_arg.name}" '
785785
f"has a default value of type {runtime_type}, "
786-
f"which is incompatible with stub argument type {stub_type}"
786+
f"which is incompatible with stub parameter type {stub_type}"
787787
)
788788
if stub_arg.initializer is not None:
789789
stub_default = evaluate_expression(stub_arg.initializer)
@@ -807,15 +807,15 @@ def _verify_arg_default_value(
807807
defaults_match = False
808808
if not defaults_match:
809809
yield (
810-
f'runtime argument "{runtime_arg.name}" '
810+
f'runtime parameter "{runtime_arg.name}" '
811811
f"has a default value of {runtime_arg.default!r}, "
812-
f"which is different from stub argument default {stub_default!r}"
812+
f"which is different from stub parameter default {stub_default!r}"
813813
)
814814
else:
815815
if stub_arg.kind.is_optional():
816816
yield (
817-
f'stub argument "{stub_arg.variable.name}" has a default value '
818-
f"but runtime argument does not"
817+
f'stub parameter "{stub_arg.variable.name}" has a default value '
818+
f"but runtime parameter does not"
819819
)
820820

821821

@@ -1013,7 +1013,7 @@ def _verify_signature(
10131013
and not is_dunder(function_name, exclude_special=True) # noisy for dunder methods
10141014
):
10151015
yield (
1016-
f'stub argument "{stub_arg.variable.name}" should be positional-only '
1016+
f'stub parameter "{stub_arg.variable.name}" should be positional-only '
10171017
f'(add "/", e.g. "{runtime_arg.name}, /")'
10181018
)
10191019
if (
@@ -1025,7 +1025,7 @@ def _verify_signature(
10251025
and not is_dunder(function_name, exclude_special=True) # noisy for dunder methods
10261026
):
10271027
yield (
1028-
f'stub argument "{stub_arg.variable.name}" should be positional or keyword '
1028+
f'stub parameter "{stub_arg.variable.name}" should be positional or keyword '
10291029
'(remove "/")'
10301030
)
10311031

@@ -1040,28 +1040,28 @@ def _verify_signature(
10401040
# If the variable is in runtime.kwonly, it's just mislabelled as not a
10411041
# keyword-only argument
10421042
if stub_arg.variable.name not in runtime.kwonly:
1043-
msg = f'runtime does not have argument "{stub_arg.variable.name}"'
1043+
msg = f'runtime does not have parameter "{stub_arg.variable.name}"'
10441044
if runtime.varkw is not None:
10451045
msg += ". Maybe you forgot to make it keyword-only in the stub?"
10461046
yield msg
10471047
else:
1048-
yield f'stub argument "{stub_arg.variable.name}" is not keyword-only'
1048+
yield f'stub parameter "{stub_arg.variable.name}" is not keyword-only'
10491049
if stub.varpos is not None:
1050-
yield f'runtime does not have *args argument "{stub.varpos.variable.name}"'
1050+
yield f'runtime does not have *args parameter "{stub.varpos.variable.name}"'
10511051
elif len(stub.pos) < len(runtime.pos):
10521052
for runtime_arg in runtime.pos[len(stub.pos) :]:
10531053
if runtime_arg.name not in stub.kwonly:
10541054
if not _is_private_parameter(runtime_arg):
1055-
yield f'stub does not have argument "{runtime_arg.name}"'
1055+
yield f'stub does not have parameter "{runtime_arg.name}"'
10561056
else:
1057-
yield f'runtime argument "{runtime_arg.name}" is not keyword-only'
1057+
yield f'runtime parameter "{runtime_arg.name}" is not keyword-only'
10581058

10591059
# Checks involving *args
10601060
if len(stub.pos) <= len(runtime.pos) or runtime.varpos is None:
10611061
if stub.varpos is None and runtime.varpos is not None:
1062-
yield f'stub does not have *args argument "{runtime.varpos.name}"'
1062+
yield f'stub does not have *args parameter "{runtime.varpos.name}"'
10631063
if stub.varpos is not None and runtime.varpos is None:
1064-
yield f'runtime does not have *args argument "{stub.varpos.variable.name}"'
1064+
yield f'runtime does not have *args parameter "{stub.varpos.variable.name}"'
10651065

10661066
# Check keyword-only args
10671067
for arg in sorted(set(stub.kwonly) & set(runtime.kwonly)):
@@ -1080,20 +1080,20 @@ def _verify_signature(
10801080
if arg in {runtime_arg.name for runtime_arg in runtime.pos}:
10811081
# Don't report this if we've reported it before
10821082
if arg not in {runtime_arg.name for runtime_arg in runtime.pos[len(stub.pos) :]}:
1083-
yield f'runtime argument "{arg}" is not keyword-only'
1083+
yield f'runtime parameter "{arg}" is not keyword-only'
10841084
else:
1085-
yield f'runtime does not have argument "{arg}"'
1085+
yield f'runtime does not have parameter "{arg}"'
10861086
for arg in sorted(set(runtime.kwonly) - set(stub.kwonly)):
10871087
if arg in {stub_arg.variable.name for stub_arg in stub.pos}:
10881088
# Don't report this if we've reported it before
10891089
if not (
10901090
runtime.varpos is None
10911091
and arg in {stub_arg.variable.name for stub_arg in stub.pos[len(runtime.pos) :]}
10921092
):
1093-
yield f'stub argument "{arg}" is not keyword-only'
1093+
yield f'stub parameter "{arg}" is not keyword-only'
10941094
else:
10951095
if not _is_private_parameter(runtime.kwonly[arg]):
1096-
yield f'stub does not have argument "{arg}"'
1096+
yield f'stub does not have parameter "{arg}"'
10971097

10981098
# Checks involving **kwargs
10991099
if stub.varkw is None and runtime.varkw is not None:
@@ -1103,9 +1103,9 @@ def _verify_signature(
11031103
stub_pos_names = {stub_arg.variable.name for stub_arg in stub.pos}
11041104
# Ideally we'd do a strict subset check, but in practice the errors from that aren't useful
11051105
if not set(runtime.kwonly).issubset(set(stub.kwonly) | stub_pos_names):
1106-
yield f'stub does not have **kwargs argument "{runtime.varkw.name}"'
1106+
yield f'stub does not have **kwargs parameter "{runtime.varkw.name}"'
11071107
if stub.varkw is not None and runtime.varkw is None:
1108-
yield f'runtime does not have **kwargs argument "{stub.varkw.variable.name}"'
1108+
yield f'runtime does not have **kwargs parameter "{stub.varkw.variable.name}"'
11091109

11101110

11111111
def _is_private_parameter(arg: inspect.Parameter) -> bool:
@@ -1425,7 +1425,7 @@ def apply_decorator_to_funcitem(
14251425
if decorator.fullname == "builtins.classmethod":
14261426
if func.arguments[0].variable.name not in ("cls", "mcs", "metacls"):
14271427
raise StubtestFailure(
1428-
f"unexpected class argument name {func.arguments[0].variable.name!r} "
1428+
f"unexpected class parameter name {func.arguments[0].variable.name!r} "
14291429
f"in {dec.fullname}"
14301430
)
14311431
# FuncItem is written so that copy.copy() actually works, even when compiled

mypy/test/teststubtest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,8 +2583,8 @@ def test_output(self) -> None:
25832583
options=[],
25842584
)
25852585
expected = (
2586-
f'error: {TEST_MODULE_NAME}.bad is inconsistent, stub argument "number" differs '
2587-
'from runtime argument "num"\n'
2586+
f'error: {TEST_MODULE_NAME}.bad is inconsistent, stub parameter "number" differs '
2587+
'from runtime parameter "num"\n'
25882588
f"Stub: in file {TEST_MODULE_NAME}.pyi:1\n"
25892589
"def (number: builtins.int, text: builtins.str)\n"
25902590
f"Runtime: in file {TEST_MODULE_NAME}.py:1\ndef (num, text)\n\n"
@@ -2599,7 +2599,9 @@ def test_output(self) -> None:
25992599
)
26002600
expected = (
26012601
"{}.bad is inconsistent, "
2602-
'stub argument "number" differs from runtime argument "num"\n'.format(TEST_MODULE_NAME)
2602+
'stub parameter "number" differs from runtime parameter "num"\n'.format(
2603+
TEST_MODULE_NAME
2604+
)
26032605
)
26042606
assert output == expected
26052607

0 commit comments

Comments
 (0)