Skip to content

Generic type alias? #1037

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

Closed
desmond-dsouza opened this issue Dec 2, 2015 · 3 comments
Closed

Generic type alias? #1037

desmond-dsouza opened this issue Dec 2, 2015 · 3 comments
Labels

Comments

@desmond-dsouza
Copy link

Not sure if this is Question or Issue. Is the IterFunc alias below allowed? There is no other way to alias a complex generic types.

from typing import TypeVar, Callable, Iterator, Iterable

T = TypeVar("T")

IterFunc = Callable[[], Iterator[T]]

def s_map(f: Callable[[T], T], l: Iterable[T]) -> IterFunc:
    return lambda: map(f, l)

Mypy rejects it with:

 Invalid type "__main__.T"

Thanks.

@JukkaL JukkaL added the feature label Dec 2, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Dec 2, 2015

It's not supported yet, but I think that PEP 484 allows it.

There is another possible interpretation of the alias that was discussed before (I can't find the issue), in which X = Dict[str, T] would make X[int] mean Dict[str, int], for example.

@gvanrossum
Copy link
Member

Yes, PEP 484 explicitly allows this. I think the other issue you're thinking of is in typehinting: python/typing#115. Also that mentions #606 here, which this is probably a duplicate of.

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 3, 2015

Yeah, this looks like a duplicate of #606. Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants