Skip to content

🐛 Methods converted to staticmethods using a decorator not treated as staticmethods #13434

Closed

Description

@tombulled

Bug Report
The @staticmethod decorator only appears to work with MyPy when used as a decorator.

For example, the following code works:

class MyClass:
    @staticmethod
    def my_method():
        ...

However, the following code does not work:

from typing import Callable


def make_staticmethod(func: Callable, /) -> staticmethod:
    return staticmethod(func)

class MyClass:
    @make_staticmethod
    def my_method():
        ...

The above code produces the following error:

error: Method must have at least one argument

To Reproduce

  1. Run MyPy against the non-working example shown above

Expected Behavior
MyPy sees that the decorator returns a staticmethod and proceeds to treat MyClass.my_method as a staticmethod

Actual Behavior
MyPy produces the following error:

error: Method must have at least one argument

The above error implies that MyPy is not treating the method as a staticmethod.

Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.8.10
  • Operating system and version: Linux Mint 20.3 x86_64

Activity

  1. added
    topic-descriptorsProperties, class vs. instance attributes
    and removed
    bugmypy got something wrong
    on Aug 20, 2022
  2. RivenSkaye commented on Nov 18, 2022

    @RivenSkaye

    I've noticed this too, for both staticmethod and classmethod. Which is a shame, because application order of decorators can cause some funky stuff to happen, including but not limited to straight up errors at runtime, or typehints breaking down to *args: Any, **kwargs: Any.
    If you do add arguments to the functions, the error changes to a warning that there is no self or cls argument.
    Tangentially related, both of those decorators return object instances of their specific classes that are seen as e.g. staticmethod[int], but trying to hint a function or method as returning such a function causes a runtime error due to the classes not being subscriptable.
    I think a possible solution would be typing entries for StaticMethod[] (and perhaps for typing_extensions too?) and ClassMethod[].

    As a positive side effect, this might also stop IDE autocomplete from adding cls as a positional argument in its autocomplete, since the handling of these annotations would be different

  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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions