-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Pyright does not handle overload ambiguity #2521
Copy link
Copy link
Closed
Labels
as designedNot a bug, working as intendedNot a bug, working as intended
Description
Describe the bug
Pyright currently does not handle overload ambiguity, always defaulting to the first overload in such a situation (see below).
After its report in numpy/numpy#20265 I initially thought this might be a similar issue as python/mypy#11347,
but the fact that it seems to affect all overloaded callables makes it quite a bit more expansive.
To Reproduce
from typing import overload, Any, List
@overload
def func(a: List[int]) -> bool: ...
@overload
def func(b: List[str]) -> float: ...
list_int: List[int]
list_str: List[str]
list_any: List[Any]
# Expected behavior
reveal_type(func(list_int)) # info: Type of "func(list_int)" is "bool"
reveal_type(func(list_str)) # info: Type of "func(list_str)" is "float"
# Uhoh, it's defaulting to the first overload (quite the assumption)
reveal_type(func(list_any)) # info: Type of "func(list_any)" is "bool"Expected behavior
The return of either Any or, depending on the particular overloads, an Any-parametrized generic.
VS Code extension or command-line
- Command line (plain
pyrightcommand) - pyright 1.1.184
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
as designedNot a bug, working as intendedNot a bug, working as intended