Skip to content

Support type aliases in builtins #5338

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 1 commit into from
Jul 10, 2018

Conversation

ilevkivskyi
Copy link
Member

This fixes a recently discovered internal crash. This should probably go into the release, since this is a regression.

@ilevkivskyi ilevkivskyi requested a review from msullivan July 9, 2018 22:23
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Looks good, with a question about a future refactor possibility:

How many places do we need to do this sort of check? If it is a lot, we might want a function that we call to collapse out TypeAliases for this sort of thing.

@@ -3171,6 +3171,9 @@ def named_type(self, name: str) -> Instance:
# Assume that the name refers to a type.
sym = self.lookup_qualified(name)
node = sym.node
if isinstance(node, TypeAlias):
assert isinstance(node.target, Instance)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It can't ever be a chain of TypeAliases?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can't, chained aliases are collapsed on sight. An alias can target other types (non-Instance) but this function is supposed to be used only with built-in types, that are all instances.

@ilevkivskyi
Copy link
Member Author

How many places do we need to do this sort of check? If it is a lot, we might want a function that we call to collapse out TypeAliases for this sort of thing.

This is actually a quite common pattern. I think I have seen at least three or four other occurrences of the same pattern. I will try to factor them all out.

@ilevkivskyi
Copy link
Member Author

How many places do we need to do this sort of check? If it is a lot, we might want a function that we call to collapse out TypeAliases for this sort of thing.

This is actually a quite common pattern. I think I have seen at least three or four other occurrences of the same pattern. I will try to factor them all out.

I have found 11 places where a similar pattern is used, but the problem is that all of them are not like others (mostly we just want to detect unsubscripted aliases in different contexts, but don't rebind the node). I tried to play with it, but it looks like defining such a function will actually complicate the code.

I will then merge this one now, maybe we can revisit this refactoring later.

@ilevkivskyi ilevkivskyi merged commit e6692ca into python:master Jul 10, 2018
@ilevkivskyi ilevkivskyi deleted the fix-bytes-alias branch July 10, 2018 17:53
ilevkivskyi added a commit that referenced this pull request Jul 11, 2018
This fixes a recently discovered internal crash.
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