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

Unable to find a matching function overload #549

Closed
schperplata opened this issue Nov 2, 2020 · 4 comments
Closed

Unable to find a matching function overload #549

schperplata opened this issue Nov 2, 2020 · 4 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@schperplata
Copy link

schperplata commented Nov 2, 2020

Issue Type: Question
Is there anything obviously wrong with my type hints that VSC complains about: No overloads for "colorize(data, 'red')" match parameters?

@overload
def colorize(data: str, color: str) -> str: ...
@overload
def colorize(data: List[str], color: str) -> List[str]: ...

def colorize(data: Union[List[str], str], color: str) -> Union[List[str], str]:
    if isinstance(data, list):
        if len(data):
            data[0] = f"<div style=\"color: {color};\">{data[0]}"
            data[-1] = f"{data[-1]}</div>"
    else:
        data = f"<span style=\"color: {color};\">{data}</span>"

    return data


@overload
def inRedColor(data: str) -> str: ...
@overload
def inRedColor(data: List[str]) -> List[str]: ...


def inRedColor(data: Union[List[str], str]) -> Union[List[str], str]:
    return colorize(data, 'red')

Error:
image

Extension version: 2020.10.3
VS Code version: Code 1.50.1 (d2e414d9e4239a252d1ab117bd7067f125afd80a, 2020-10-13T15:06:15.712Z)
OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (8 x 2712)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.92GB (5.83GB free)
Process Argv W:\AsystLib\isys\python\VSCodeDevWorkspace_refactor.code-workspace --crash-reporter-id 919e0ed9-46f3-4ad4-9e28-f35755bf8266
Screen Reader no
VM 0%
@github-actions github-actions bot added the triage label Nov 2, 2020
@erictraut
Copy link
Contributor

This is related to this issue: microsoft/pyright#1119

It speaks to a subtle difference between the way pyright/pylance handle overloads versus mypy. We've talked about possibly switching to a behavior that is consistent with mypy, but it's a big code change and has potential significant performance impact.

@erictraut
Copy link
Contributor

You can easily work around the issue by adding a third overload:

@overload
def colorize(data: Union[List[str], str], color: str) -> Union[List[str], str]: ...

@erictraut
Copy link
Contributor

Reopening this issue. We've received a sufficient number of bug reports about the overload matching behavior that I decided to change the behavior to more closely match mypy's. This eliminates the need for workarounds like the one I posted above. This change will be in the next version of pylance.

@erictraut erictraut reopened this Apr 25, 2021
@erictraut erictraut added enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Apr 25, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.4.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202143-29-april-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants