Skip to content

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

@hvenev

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

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