Closed
Description
Bug Report, To Reproduce, & Actual Behaviour
When overriding an attribute created with a function definition statement in the superclass, subclasses complain about type mismatch of the function definition type itself, instead of the entire statement (that is, with all the decorators applied). See mypy Playground:
class A:
@str
def attr(self, /) -> None: ...
class B(A):
attr: str # mypy: Incompatible types in assignment (expression has type "str", base class "A" defined the type as "Callable[[A], None]") [assignment]
This is an artificial but minimum example; the actual use case is for a custom descriptor which has similar flexibility to builtins.property
, allowing declaration & definition with both decorators (like @property
) and assignments (like attr = property(...)
).
Expected Behavior
No issues
Your Environment
- Mypy version used: 1.10.1, master
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10, 3.12