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

singledispatch and TypeVar return type #5560

Open
vnmabus opened this issue May 31, 2021 · 3 comments
Open

singledispatch and TypeVar return type #5560

vnmabus opened this issue May 31, 2021 · 3 comments

Comments

@vnmabus
Copy link

vnmabus commented May 31, 2021

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.

@srittau srittau added the reason: inexpressable Closed, because this can't be expressed within the current type system label May 31, 2021
@srittau
Copy link
Collaborator

srittau commented May 31, 2021

Unfortunately, I don't see a way to express this using the current type system. This is possibly something where PEP 646 can help with. For now, I will marks this as "inexpressable" and close it, but we can revisit this if and when a solution becomes available in the type system.

@srittau srittau closed this as completed May 31, 2021
@srittau
Copy link
Collaborator

srittau commented May 31, 2021

Or possibly PEP 612, for which we have a tracker issue: #4827.

@srittau srittau removed the reason: inexpressable Closed, because this can't be expressed within the current type system label Sep 27, 2021
@srittau
Copy link
Collaborator

srittau commented Sep 27, 2021

Reopening as PEP 612 is now mostly available.

@srittau srittau reopened this Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants