-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
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)
evfinkn
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong