Skip to content

Pyright does not handle overload ambiguity #2521

@BvB93

Description

@BvB93

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 pyright command)
  • pyright 1.1.184

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions