Skip to content
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

Regression: false positive about overload item never being matched #16338

Closed
JukkaL opened this issue Oct 27, 2023 · 1 comment · Fixed by #16343
Closed

Regression: false positive about overload item never being matched #16338

JukkaL opened this issue Oct 27, 2023 · 1 comment · Fixed by #16343
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-overloads

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 27, 2023

This fragment generates a false positive, starting from #15913:

from typing import overload, Any

class C:
    @overload
    def f(self, e: str, **kwargs) -> str: ...
    @overload
    # error: Overloaded function signature 2 will never be matched: signature 1's
    #        parameter type(s) are the same or broader
    def f(self, *args, **kwargs) -> Any: ...
    def f(self, *args, **kwargs):
        pass

The signature of item 2 is wider than item 1 due to accepting an arbitrary number of positional arguments and with arbitrary types, so this is a false positive.

cc @ilevkivskyi

@JukkaL JukkaL added bug mypy got something wrong false-positive mypy gave an error on correct code topic-overloads labels Oct 27, 2023
@JukkaL JukkaL mentioned this issue Oct 27, 2023
2 tasks
@ilevkivskyi
Copy link
Member

This is one of those case when I ask myself how did this ever work, and it turns out it didn't. It turns out having (*args: Any, **kwargs: Any) as a fallback overload caused false positives almost always. So this is not really a regression, now mypy is consistently broken, LOL.

Anyway, the fix is in #16343, it turns out we never propagated is_proper_subtype flag to is_callable_compatible(). This is a major change, let's see how bad the fallout will be.

ilevkivskyi added a commit that referenced this issue Oct 27, 2023
Fixes #16338

This is kind of a major change, but it is technically correct: we should
not treat `(*args: Any, **kwargs: Any)` special in `is_proper_subtype()`
(only in `is_subtype()`). Unfortunately, this requires an additional
flag for `is_callable_compatible()`, since currently we are passing the
subtype kind information via a callback, which is not applicable to
handling argument kinds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code topic-overloads
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants