Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy