-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes
Description
Bug Report
When a class C defines an attribute a to be a union type with Callable as one of its types (a: Callable | ...), mypy incorrectly marks a @staticmethod definition of a in a child class that inherits from C to be incompatible with a's signature in C.
Worth noting that the following code produces no errors:
from typing import Callable
class Parent:
foo: Callable[[str], str]
class Child2(Parent):
@staticmethod
def foo(x: str) -> str:
return x.lower()but the following code does
from typing import Callable
class Parent:
foo: Callable[[str], str] | str
class Child1(Parent):
foo = "bar" # OK
class Child2(Parent):
@staticmethod
def foo(x: str) -> str: # Signature of "foo" incompatible with supertype "Parent"
return x.lower()Expected Behavior
No errors.
Actual Behavior
example.py: note: In class "Child2":
example.py:14: error: Signature of "foo" incompatible with supertype "Parent" [override]
Found 1 error in 1 file (checked 1 source file)Environment
- Mypy version used:
0.941 - Mypy command-line flags:
--strict,--show-error-codes,--show-error-context - Mypy configuration options from
mypy.ini(and other config files): - Python version used:
3.10.3 - Operating system and version: MacOS 12.3
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes