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

partial plugin does not handle overloads #17585

Open
asottile-sentry opened this issue Jul 25, 2024 · 2 comments
Open

partial plugin does not handle overloads #17585

asottile-sentry opened this issue Jul 25, 2024 · 2 comments
Labels
bug mypy got something wrong

Comments

@asottile-sentry
Copy link

Bug Report

it appears the new partial plugin added in mypy 1.11 doesn't properly handle overloads (and just picks the first one)

To Reproduce

import functools
from typing import assert_type, overload

@overload
def identity(x: int, *, p: str) -> int: ...
@overload
def identity(x: str, *, p: str) -> str: ...
def identity(x: int | str, *, p: str) -> int | str: return x


p = functools.partial(identity, p='hi')
assert_type(p(1), int)
assert_type(p('hi'), str)

Expected Behavior

(no errors)

Actual Behavior

$ mypy t.py 
t.py:13: error: Expression is of type "int", not "str"  [assert-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.11.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12.2
@asottile-sentry asottile-sentry added the bug mypy got something wrong label Jul 25, 2024
@asottile-sentry
Copy link
Author

an alternative spelling with TypeVars seems to not work either:

import functools
from typing import assert_type, overload, TypeVar

T = TypeVar("T", int, str)

def identity(x: T, *, p: str) -> T: return x


p = functools.partial(identity, p='hi')
assert_type(p(1), int)
assert_type(p('hi'), str)
$ ./venv/bin/mypy t.py 
t.py:10: error: Expression is of type "Any", not "int"  [assert-type]
t.py:11: error: Expression is of type "Any", not "str"  [assert-type]
Found 2 errors in 1 file (checked 1 source file)

asottile-sentry added a commit to getsentry/sentry that referenced this issue Jul 25, 2024
asottile-sentry added a commit to getsentry/sentry that referenced this issue Jul 25, 2024
Christinarlong pushed a commit to getsentry/sentry that referenced this issue Jul 26, 2024
@hauntsaninja
Copy link
Collaborator

Yes, the behaviour with overloads is unchanged from mypy 1.10. Shouldn't be too bad to add support for it.

# TODO: handle overloads, just fall back to whatever the non-plugin code does
return ctx.default_return_type

The constrained type var example you have is a duplicate of #17411. Note that unconstrained type vars or bounded type vars should work correctly. In general, mypy's handling of constrained type vars is a little weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants