Skip to content

Autocomplete of Literal value only takes last overload into account #4428

@friedererdmann

Description

@friedererdmann

Describe the bug
In our code base we have a function which returns different objects based on a string provided as parameter. To provide good auto complete, our stubs make use of Literal and overload.

image

However, without the quotation marks, it does show all the possible outputs, but you can't use these to automatically fill the parameter:

image

To Reproduce
Create a function example and overload it with different Literal values. When calling the function now you can start typing quotation marks to see the possible strings to type, but you'll only be offered the last possible overload.

Expected behavior
All overloads should be offered to the autocompletion

Screenshots or Code

from typing import overload, Literal


@overload
def example(parameter: Literal["int"]) -> int: ...


@overload
def example(parameter: Literal["bool"]) -> bool: ...


@overload
def example(parameter: Literal["str"]) -> str: ...


def example(parameter):
    # some logic here
    return parameter


example("")

VS Code extension or command-line
Using PyLance as a VSCode extension (which includes Pyright (?))

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestneeds investigationCould be an issue - needs investigation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions