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

Parameter suggestion uses only the last overload for overloaded functions #6930

Open
rchiodo opened this issue Feb 7, 2025 · 0 comments
Open
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Feb 7, 2025

Discussed in #6928

Originally posted by adrien-lsh February 7, 2025
Hi there,

I recently started to type hint the functions of my project. And some of them return certain types depending of the value of a parameter.
When overloading these functions to have accurate types, I found out that my lsp only suggests one of the two possibilities.

Pylance.issue.mp4

Python 3.12.2
Neovim v0.10.4
Pyright 1.1.393

from typing import Literal, overload


@overload
def foo(return_type: Literal['dict']) -> dict: ...  
@overload
def foo(return_type: Literal['list']) -> list: ...

def foo(return_type: Literal['dict', 'list']) -> dict | list:
    if return_type == 'dict':
        return {}
    return []

foo('')
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants