Describe the bug
When a base class has a Callable variable without a Self parameter, overriding this variable in a subclass causes an error, which is inconsistent with the behavior of mypy and ty.
Code or Screenshots
from collections.abc import Callable
from typing import override
class A:
hello: Callable[[], None] = lambda: print("hello")
class B(A):
@override
def hello(self) -> None:
print("hi")
b = B()
b.hello()
# Output: hi
(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> pyright main4.py
g:\programming\python\lab\report_callback_exception\main4.py
g:\programming\python\lab\report_callback_exception\main4.py:11:9 - error: Method "hello" overrides class "A" in an incompatible manner
Positional parameter count mismatch; base method has 0, but override has 1 (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations
(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> mypy main4.py
Success: no issues found in 1 source file
(report-callback-exception) PS G:\programming\python\lab\report_callback_exception> ty check main4.py
All checks passed!
VS Code extension or command-line
- mypy=2.1.0
- pyright=1.1.409
- ty=0.0.40
Describe the bug
When a base class has a Callable variable without a
Selfparameter, overriding this variable in a subclass causes an error, which is inconsistent with the behavior of mypy and ty.Code or Screenshots
VS Code extension or command-line