-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
reportIncompatibleMethodOverride and typevartuples #4118
Comments
@erictraut why isn't this considered as a bug ? |
This is considered an enhancement request because |
I've looked and debugged the algorithm in validating *argsAs I understand it, the logic when validating positional arguments is:
I think we can make this a little bit more strict by changing the rule to:
class Parent:
def my_method41(self, a: int, b: str) -> None:
...
def my_method42(self, a: int, b: str) -> None:
...
class Child:
# this should not generate an error because args is of the right type
def my_method41(self, a: int, *args: str) -> None:
...
# this should generate an error because args doesn't have the right type
def my_method42(self, a: int, *args: int) -> None:
... UnpackI think there is a bug, in the way unpacked args are handled. class Parent(Generic[Unpack[Ts]]):
def method_1(self, *args: Unpack[Ts]) -> None:
...
def method_2(self, *args: Unpack[tuple[Unpack[Ts]]]) -> None:
...
class Child(Parent[int]):
def method_1(self, arg1: int) -> None: # this is not reported as an error. It makes sense.
...
def method_2(self, arg1: int) -> None: # this is reported as an error, although method_1 are strictly equivalent
... I think this is because Parent.method_1 parameters (baseType.details.parameters) are evaluated as
while
If you're OK with this approach, I can submit a PR for the first point, and try to find a fix for item n°2 (though i need to look closer to understand why unpacked and typevartuples seem to be handled by different parts of the code) |
I'd prefer that you don't make changes to this code. This is one of the more complex pieces of code in pyright, so I'd prefer to do it myself. It will take me longer to review and verify a PR than it will to implement it myself. I'll get to this eventually, but I don't consider it a high priority because it's an enhancement request and a false negative. |
Alright ! The second point does seem a bit tricky. The first is fairly straightforward from what I've seen. I understand you consider the enhancement part low prio. But I still believe there is a bug in the second part that I described :). It's a false positive, and not a false negative. |
…ibleMethodOverride` check when the base method used an unpacked `tuple` for the `*args` parameter and the override used specific parameters. This addresses part of #4118.
One of the (many) complexities that PEP 646 added was that it broke the invariant that positional-only parameters must always precede parameters that can be used as keyword-only parameters. For example, This doesn't yet address the enhancement request part. There are reasons why the |
Thanks for the quick fix ! |
…ere an override uses an `*args` parameter that is not type compatible with the overridden method's parameter types. Thanks to @mehdigmira for this contribution. This addresses #4118.
This will be addressed in the next release. I used your code largely unchanged. Thanks for the contribution. |
This is included in pyright 1.1.286, which I just published. It will also be included in a future version of pylance. |
Describe the bug
It seems to me reportIncompatibleMethodOverride is not working as expected when using typevartuples.
To Reproduce
Expected behavior
Child should be reported as an error. Child3 should not.
VS Code extension or command-line
pyright 1.1.277
The text was updated successfully, but these errors were encountered: