Repository navigation
Support type aliases in builtins - #5338
Conversation
msullivan
left a comment
There was a problem hiding this comment.
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.
| sym = self.lookup_qualified(name) | ||
| node = sym.node | ||
| if isinstance(node, TypeAlias): | ||
| assert isinstance(node.target, Instance) |
There was a problem hiding this comment.
It can't ever be a chain of TypeAliases?
There was a problem hiding this comment.
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.
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. |
This fixes a recently discovered internal crash.
This fixes a recently discovered internal crash. This should probably go into the release, since this is a regression.