Skip to content

checker: say "parameter" instead of "argument" in missing-self diagnostic (#20939)#21452

Open
jbbqqf wants to merge 1 commit intopython:masterfrom
jbbqqf:feat/20939-method-parameter-wording
Open

checker: say "parameter" instead of "argument" in missing-self diagnostic (#20939)#21452
jbbqqf wants to merge 1 commit intopython:masterfrom
jbbqqf:feat/20939-method-parameter-wording

Conversation

@jbbqqf
Copy link
Copy Markdown

@jbbqqf jbbqqf commented May 9, 2026

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 already
uses "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:

A method with no parameter gets the wrong error message saying
argument instead of parameter.

The diagnostic is raised in mypy/checker.py (currently
TypeChecker.check_method_or_accessor_override_for_base → see
mypy/checker.py:1755 on master) when a non-static method's signature
has 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 master against the new wording and pass on
this branch.

Reproduce BEFORE/AFTER yourself (copy-paste)

# --- one-time setup ---
python3 -m venv /tmp/repro-20939-env
source /tmp/repro-20939-env/bin/activate
pip install -q --upgrade pip

cat > /tmp/repro-20939.py <<'PY'
class Cls:
    def meth(): ...
PY

# --- BEFORE (origin/master) ---
pip install -q --force-reinstall --no-deps \
  "git+https://github.com/python/mypy.git@master"
mypy --no-incremental --cache-dir=/tmp/repro-20939-cache-before /tmp/repro-20939.py
# Expected: error contains 'Method must have at least one argument. Did you forget the "self" argument?'

# --- AFTER (this PR) ---
pip install -q --force-reinstall --no-deps \
  "git+https://github.com/jbbqqf/mypy.git@feat/20939-method-parameter-wording"
mypy --no-incremental --cache-dir=/tmp/repro-20939-cache-after /tmp/repro-20939.py
# Expected: error contains 'Method must have at least one parameter. Did you forget the "self" parameter?'

The only thing that changes between the two halves is the installed
mypy ref. The same mypy /tmp/repro-20939.py command 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.pyAll checks passed.
  • black --check mypy/checker.pyclean.
  • BEFORE/AFTER reproducer (block above) — manually verified end-to-end.

Edge cases tested

# Scenario Input Expected Verified by
1 Method with empty parameter list class C: def m(): ... new wording emitted reproducer block + existing fixture check-classes.test:7832
2 @property-decorated method with no params @property\ndef g() -> int: pass new wording emitted check-functions.test:2802
3 Nested-class method missing self (fine-grained reprocess) testReprocessMethodInNestedClassSemanal new wording emitted across reprocess passes fine-grained.test:1996–2000
4 @staticmethod (suppresses diagnostic) static method without self no diagnostic preserved by guard at mypy/checker.py:1748 (unchanged)
5 Method with *args / **kwargs only def m(*args, **kwargs) no diagnostic (well-formed) guard at mypy/checker.py:1749 (unchanged)

Risk / blast radius

  • Wording-only change. No type-checker behaviour or error code changes.
  • Downstream consumers that grep mypy output for the exact old
    string Method must have at least one argument. Did you forget the "self" argument? will stop matching. This is the common cost of any
    message-wording fix; given that message_registry.py:227 already
    uses "parameter" for the parallel diagnostic, the new wording is the
    more consistent target.
  • All in-tree tests that assert the message have been updated in the
    same commit.

Release note

Diagnostic for a method with no parameters now says "parameter"
("Method must have at least one parameter. Did you forget the 'self'
parameter?") instead of "argument", matching the wording used by the
sibling 'self parameter missing' diagnostic.

PR drafted with assistance from Claude Code. The change was reviewed
manually against python/mypy's master branch, the
mypy/message_registry.py:227 parallel diagnostic, and the CPython
parameter/argument glossary. The reproducer block above was used during
development and is the same one a reviewer can paste verbatim.

…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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A method with no parameter gets a wrong error message saying argument instead of parameter

1 participant