Skip to content

error when using overload and providing a default to callable parameter #5306

@rcarpa

Description

@rcarpa

Describe the bug
Hi team, the following code generates a warning and an error on pyright 1.1.314

warning: Type variable "_T" may go unsolved if caller supplies no argument for parameter "fnc"

and

error: Overloaded implementation is not consistent with signature of overload 2
    Type "(var: Unknown, fnc: (x: Unknown) -> Unknown = lambda x: x) -> Unknown" cannot be assigned to type "(var: str, fnc: (str) -> _T@convert = ...) -> _T@convert"
      Parameter 2: type "(str) -> _T@convert" cannot be assigned to type "(x: Unknown) -> Unknown"
        Type "(str) -> _T@convert" cannot be assigned to type "(x: Unknown) -> Unknown"
          Position-only parameter mismatch; expected 1 but received 0 (reportGeneralTypeIssues)

both of which seem incorrect to me, considering that the code provides an overload without the given argument; and that there is no parameter number mismatch.

Code or Screenshots

from typing import overload, Callable, TypeVar

_T = TypeVar('_T')


@overload
def convert(var: str) -> str:
    ...

@overload
def convert(var: str, fnc: Callable[[str], _T] = ...) -> _T:
    ...

def convert(var, fnc=lambda x: x):
    return fnc(var)


print(convert('5', int))

Is it a bug on the pyright side, or am I doing something incorrectly ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions