Description
Consider the following program:
# test.py
class Outer:
class Inner: pass
Alias = Outer
x: Alias.Inner
reveal_type(x)
Mypy thinks that the type of x
is test.Outer
instead of test.Outer.Inner
. We get this behavior with both the new and old semantic analyzers.
It seems the root cause has to do with the lookup_qualified
function -- when the loop encounters a SymbolNode of type TypeAlias, it effectively stops processing the parts
variable, ignoring any subsequent information in that list. So, we drop everything to the right of the first type alias.
There's actually a TODO about this in the code, though it points out the issue for only Var
and FuncDef
. The new semantic analyzer's lookup_qualified
uses the same algorithm + has the same TODO.
In order to fix this correctly, we'll maybe need to either transfer the unhandled parts back to the caller, or move the type alias expansion logic from typeanal
into this function? I briefly experimented with both approaches, but they both seemed very clunky.
Probably the right thing to do is to just fix this as a part of the long-awaited lookup-functions-refactor (#4157).
(Hopefully this isn't a dupe -- I'm mostly filing this so I can link to it in a PR I'm preparing.)