Skip to content

Erroneous "Self argument missing" error when decorators are used #19392

Closed

Description

@hvenev

Bug Report

mypy sometimes erroneously emits a "Self argument missing" error on function definitions inside class definitons. See the example below.

If the function has no paramters, the error is "Method must have at least one argument.". Again, it does not matter what the decorator does to the function.

To Reproduce

import typing

def apply_on_answer[T](f: typing.Callable[[int], T], /) -> T:
    return f(42)

class C:
    @apply_on_answer
    def x(answer: int) -> int:
        return answer

assert type(C.x) is int
assert C.x == 42

Expected Behavior
mypy should emit no errors.

Actual Behavior
mypy emits the following error:

a.py:8: error: Self argument missing for a non-static method (or an invalid type for self)  [misc]

Your Environment

  • Mypy version used: cb3bddd
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): ``
  • Python version used: 3.13.5

Activity

  1. changed the title [-]Errnoeous "Self argument missing" error when decorators are used[/-] [+]Erroneous "Self argument missing" error when decorators are used[/+] on Jul 7, 2025
  2. sterliakov commented on Jul 11, 2025

    @sterliakov
    Collaborator

    Decorators that turn a callable method into a non-callable are exceptionally rare, mypy does not support this usecase. We expect any (decorated or not) method defined in class body to be just that - a method - and check accordingly.

    Note that mypy understands that C.x is an integer, even in class body (playground), the only false positive is checking selftype too eagerly. You can safely put an ignore comment there, it should not affect further typechecking.

  3. added a commit that references this issue on Jul 28, 2025
    ad76e16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions