Skip to content

Allow omitting redundant Generic[T] in base classes #2811

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

Merged
merged 4 commits into from
Feb 7, 2017

Conversation

ilevkivskyi
Copy link
Member

Fixes #302

This PR allows omitting Generic[T, ...] if there are other generics in bases:

class Stream(Iterable[T]):
    ...

The rules are as per PEP 484:

  • If Generic[...] is present, then it should list all type variables (or more). In this case the order of variables is determined by their order in Generic[...]
  • If there are no Generic[...] in bases, then all type variables are collected in lexicographic order (i.e. by first appearance)

@gvanrossum You might be interested in this.


def get_tvars(self, tp: Type) -> List[Tuple[str, TypeVarExpr]]:
tvars = [] # type: List[Tuple[str, TypeVarExpr]]
if isinstance(tp, UnboundType):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unanalyzed types can also contain TypeList instances and these should be handled here as well. For example, class A(B[Callable[[T], S]]): ... would have T inside a TypeList.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I forgot about TypeList, fixed this in a new commit.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 7, 2017

Thanks! Looks good!

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

Successfully merging this pull request may close these issues.

2 participants