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

functools.partial can't infer the return type of generic type fucntion #15053

Open
monchin opened this issue Apr 14, 2023 · 0 comments
Open

functools.partial can't infer the return type of generic type fucntion #15053

monchin opened this issue Apr 14, 2023 · 0 comments
Labels
bug mypy got something wrong

Comments

@monchin
Copy link

monchin commented Apr 14, 2023

Hello, I found that mypy can't infer to right return type when there is a generic type function in partial. Below is the code:

from functools import partial
from typing import List

def test(val:float, step:float, range_:List[float]) -> float:
    assert step != 0
    op = partial(max, range_[0]) if step > 0 else partial(min, range_[1])
    return op(val) # error: Incompatible return value type (got "SupportsRichComparisonT", expected "float")  [return-value]
    # return max(val, range_[0]) # OK

if __name__ == '__main__':
    print(test(5,-1, [3,6]))

It seems that partial will infer to the generic return type of max and min, i.e., "SupportsRichComparisonT", but it should infer to float because args in max nad min are floats.

Programs version:

  • Python 3.10.1
  • mypy 1.2.0 (compiled: yes)
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

1 participant