checker: say "parameter" instead of "argument" in missing-self diagnostic (#20939)#21452
Open
jbbqqf wants to merge 1 commit intopython:masterfrom
Open
checker: say "parameter" instead of "argument" in missing-self diagnostic (#20939)#21452jbbqqf wants to merge 1 commit intopython:masterfrom
jbbqqf wants to merge 1 commit intopython:masterfrom
Conversation
…stic The diagnostic emitted when a method has zero parameters is generated at definition time, so "self" is a parameter (not an argument supplied at a call site). Align the wording with mypy/message_registry.py:227, which already uses "parameter" for the parallel "missing self parameter" diagnostic. Existing tests across check-classes.test, check-functions.test, check-super.test and fine-grained.test that assert this message have been updated to the new wording; they continue to act as regression coverage. Fixes python#20939. Co-Authored-By: Claude Code <noreply@anthropic.com>
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: zope.interface (https://github.com/zopefoundation/zope.interface)
- src/zope/interface/interfaces.py:113: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:113: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:144: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:144: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:164: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:164: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:181: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:181: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:399: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:399: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:423: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:423: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:427: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:427: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:464: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:464: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:1250: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:1250: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:1334: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:1334: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:1425: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:1425: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/interfaces.py:1503: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/interfaces.py:1503: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/sequence.py:158: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/sequence.py:158: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:83: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:83: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:87: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:87: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:91: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:91: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:95: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:95: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:117: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:117: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:136: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:136: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/mapping.py:156: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/mapping.py:156: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:83: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:83: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:139: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:139: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:148: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:148: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:155: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:155: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:164: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:164: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:173: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:173: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:192: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:192: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:199: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:199: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:202: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:202: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:234: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:234: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:257: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:257: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:343: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:343: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:346: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:346: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:354: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:354: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:402: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:402: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:406: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:406: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:411: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:411: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:414: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:414: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:417: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:417: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:420: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:420: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:426: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:426: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:433: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:433: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:441: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:441: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:462: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:462: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:469: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:469: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:535: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:535: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:544: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:544: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:553: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:553: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:563: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:563: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/idatetime.py:573: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/idatetime.py:573: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
- src/zope/interface/common/tests/test_collections.py:132: error: Method must have at least one argument. Did you forget the "self" argument? [misc]
+ src/zope/interface/common/tests/test_collections.py:132: error: Method must have at least one parameter. Did you forget the "self" parameter? [misc]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The "missing self" diagnostic emitted at method-definition time currently
says argument twice, but in CPython terminology a value declared in a
function header is a parameter (an argument is what a caller
supplies). The wording change brings this single string into line with
the parallel diagnostic in
mypy/message_registry.py:227, which alreadyuses "parameter":
'"self" parameter missing for a non-static method (or an invalid type for self)'Fixes #20939.
Context
The issue (filed by @kavik2002) flags the inconsistency:
The diagnostic is raised in
mypy/checker.py(currentlyTypeChecker.check_method_or_accessor_override_for_base→ seemypy/checker.py:1755onmaster) when a non-static method's signaturehas zero declared parameters. At that point the type checker is
reasoning about the definition, not a call, so the noun "argument" is
wrong; "parameter" matches both the CPython glossary and mypy's own
sibling message.
Changes
mypy/checker.py— change the message string to use"parameter" twice. A short comment in the code records why the
wording changed (so a future reader doesn't re-derive the
parameter-vs-argument distinction from scratch).
test-data/unit/check-classes.test— 13 fixture lines updated.test-data/unit/check-functions.test— 1 fixture line updated.test-data/unit/check-super.test— 1 fixture line updated.test-data/unit/fine-grained.test— 6 fixture lines updated.The existing fixtures that assert this message become the regression
coverage: they fail on
masteragainst the new wording and pass onthis branch.
Reproduce BEFORE/AFTER yourself (copy-paste)
The only thing that changes between the two halves is the installed
mypy ref. The same
mypy /tmp/repro-20939.pycommand runs both times.What I ran locally
pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-classes.test mypy/test/testcheck.py::TypeCheckSuite::check-functions.test mypy/test/testcheck.py::TypeCheckSuite::check-super.test→ 908 passed, 1 xfailed (the xfail is preexisting and unrelated to
this change).
pytest -n0 -k "testPreviousErrorInMethodSemanal or testReprocessMethodInNestedClassSemanal" mypy/test/→ 4 passed, 4 skipped (the skips are the cache variants, also
preexisting behaviour).
ruff check mypy/checker.py→ All checks passed.black --check mypy/checker.py→ clean.Edge cases tested
class C: def m(): ...check-classes.test:7832@property-decorated method with no params@property\ndef g() -> int: passcheck-functions.test:2802testReprocessMethodInNestedClassSemanalfine-grained.test:1996–2000@staticmethod(suppresses diagnostic)mypy/checker.py:1748(unchanged)*args/**kwargsonlydef m(*args, **kwargs)mypy/checker.py:1749(unchanged)Risk / blast radius
string
Method must have at least one argument. Did you forget the "self" argument?will stop matching. This is the common cost of anymessage-wording fix; given that
message_registry.py:227alreadyuses "parameter" for the parallel diagnostic, the new wording is the
more consistent target.
same commit.
Release note
PR drafted with assistance from Claude Code. The change was reviewed
manually against
python/mypy'smasterbranch, themypy/message_registry.py:227parallel diagnostic, and the CPythonparameter/argument glossary. The reproducer block above was used during
development and is the same one a reviewer can paste verbatim.