-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Parameter 2 type mismatch: base parameter is type "Any", override parameter is type "Any" with interface methods #1787
Comments
The current behavior is correct, or at least as intended. The intention behind the "reportIncompatibleMethodOverride" check is to detect cases where a base class is making assumptions that a subclass is violating. In your example above, I think you have a few options here:
|
Hello. I also encountered this issue and tried to address it, but option 2 is not working. What should I do? from typing import Any, Callable
class A(object):
def _foo_unimplemented(self, input: Any) -> None:
raise NotImplementedError
foo: Callable[..., Any] = _foo_unimplemented
class B(A):
def foo(self):
pass
# Result:
# Method "foo" overrides class "A" in an incompatible manner
# Positional parameter count mismatch; base method has 2, but override has 1
# Parameter "args" is missing in override (reportIncompatibleMethodOverride)
class C(A):
def foo(self, *args: Any):
pass
# Result:
# Method "foo" overrides class "A" in an incompatible manner
# Positional parameter count mismatch; base method has 2, but override has 2 (reportIncompatibleMethodOverride)
class D(A):
def foo(self, *args: Any, **kwargs: Any):
pass
# Result:
# Method "foo" overrides class "A" in an incompatible manner
# Positional parameter count mismatch; base method has 2, but override has 3 (reportIncompatibleMethodOverride) |
Yeah, I would expect option 2 to work in this case. It doesn't because of the I've made this change, and it will be included in the next release. |
…to exempt the case where the base class or override has a type that is defined by `Callable[..., X]`. The `...` means that it's compatible with any signature. Also fixed a false negative in this check where the base method contains a `**kwargs` parameter but the override does not. This addresses #1787.
This is addressed in pyright 1.1.306, which I just published. It will also be included in a future release of pylance. |
This is a somewhat niche problem, but I have come across it in practice twice already. It seems like the issue is caused by unimplemented methods in the base class which have type annotations being implemented in sub-classes. The resulting error looks like this:
Adding the "Any" annotation doesn't seem to help either.
Sample code which causes the issue
The text was updated successfully, but these errors were encountered: