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
Bug Report
When a class C defines an attribute a to be a union type with
Callableas one of its types (a: Callable | ...), mypy incorrectly marks a@staticmethoddefinition 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:
but the following code does
Expected Behavior
No errors.
Actual Behavior
Environment
0.941--strict,--show-error-codes,--show-error-contextmypy.ini(and other config files):3.10.3