Skip to content

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

@tombulled

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions