Skip to content

Mypy doesn't recognize @staticmethod-like decorator #18989

Open
@yunline

Description

@yunline

File: testlib.pyi
( Copied from builtins.pyi )

import sys

from typing import Callable, Generic, overload, ParamSpec,TypeVar
_P = ParamSpec("_P")
_R_co = TypeVar("_R_co", covariant=True)
_T = TypeVar("_T")

# exactly same type alias as built-in staticmethod
class mystaticmethod(Generic[_P, _R_co]):
    @property
    def __func__(self) -> Callable[_P, _R_co]: ...
    @property
    def __isabstractmethod__(self) -> bool: ...
    def __init__(self, f: Callable[_P, _R_co], /) -> None: ...
    @overload
    def __get__(self, instance: None, owner: type, /) -> Callable[_P, _R_co]: ...
    @overload
    def __get__(self, instance: _T, owner: type[_T] | None = None, /) -> Callable[_P, _R_co]: ...
    if sys.version_info >= (3, 10):
        __name__: str
        __qualname__: str
        @property
        def __wrapped__(self) -> Callable[_P, _R_co]: ...
        def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...

File: test.py

import testlib

class MyClass:
    @staticmethod
    def default_static(): # no error
        pass

    @testlib.mystaticmethod
    def my_static(): # error
        pass

Run mypy .\test.py

test.py:9: error: Method must have at least one argument. Did you forget the "self" argument?  [misc]
Found 1 error in 1 file (checked 1 source file)

Expected behavior: methods using testlib.mystaticmethod should pass the check just like methods using staticmethod

Mypy version: mypy 1.15.0 (compiled: yes)
Python: 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions