-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy on python 3.9 does not support @staticmethod in Protocols #15257
Comments
note that using from __future__ import annotations
from typing import Protocol
class Demo(Protocol):
@staticmethod
def demo(v: int) -> int:
pass
def returns_one(v: int) -> int:
return 1
class Inheriting(Demo):
@staticmethod
def demo(v: int) -> int:
return 1 |
Likely "culprit" is python/typeshed#9771: def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ... which makes ... staticmethods overridable with regular callables? @AlexWaygood tl;dr on why |
Python 3.9 doesn't have
but that shouldn't be considered by mypy because it's called via |
Staticmethods aren't callable on Python 3.9! The x = staticmethod(lambda: 42)
class Foo:
@staticmethod
def bar(): return 42
y = Foo.__dict__['bar'] ... then you'll find that both |
FWIW I also don't understand how the presence of |
I think this bug is just a specific manifestation of #4574. Looks like the same bug to me. |
Still unclear to me why it's "fixed" with the addition of |
I'd imagine it's because mypy applies some special-casing to methods decorated with As such, because it (incorrectly) sees methods decorated with |
Bug Report
(A clear and concise description of what the bug is.)
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.9&gist=1438683686842d8a03bfbc32646c7952&flags=strict
Expected Behavior
Success: no issues found in 1 source file
Actual Behavior
main.py:15: error: Incompatible types in assignment (expression has type "staticmethod[[int], int]", base class "Demo" defined the type as "Callable[[int], int]") [assignment]
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: