Skip to content

singledispatch and TypeVar return type #5560

@vnmabus

Description

@vnmabus

It seems that singledispatch typing is not very accurate. In particular, it does not respect TypeVar used in the return type:

T = TypeVar("T")

@singledispatch
def my_fun(
    val: T,
) -> List[T]:
    return list(val)

my_fun(5)
my_fun("Ĝis la revido!")

Here the type of the returned value would always be revealed as List[T] instead of different types for different inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions