Skip to content

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

Closed

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

Activity

  1. sterliakov commented on Apr 28, 2025

    @sterliakov
    Collaborator

    Is it a dupe of #18968 with s/classmethod/staticmethod/? They are handled at the same place (early semanal), the logic for determining the type of first argument of a method is hardcoded to buitlins.{static,class}method.

  2. 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 wrongtopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions