You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support type aliases in fine-grained incremental mode #4394
[case testAliasUpdate]
import b
[file a.py]
N = int
x = 1
[file a.py.2]
N = str
x = 'hi'
[file b.py]
import a
def f(x: a.N) -> None:
pass
f(a.x)
[out]
==
The challenge here is that type aliases are completely replaced during semantic analysis, and thus we can't easily determine which type aliases were used after the fact. Here are two approaches for resolving this:
Create a new type for type alias references that doesn't get simplified away during semantic analysis.
Collect all expanded type aliases during semantic analysis and store them so that they can be used in dependency generation. For example, collect a dictionary from target to set of type aliases used.
The first approach would likely require pretty major changes to mypy, since each Type object might need to be dereferenced to get the actual effective type. I prefer the second approach due to its simplicity, though it's a little hacky.
There is a related issue #4082, but I think these two are independent. The other issue is about having it clear in the symbol table (not via type_override and other hacks), but the question about what to do about expanded types is different. I agree that option 2 is a bit hacky, but we did conceptually similar thing for forward references and it seems to work well. So I am fine with option 2 (also it is easy to implement).
Activity
msullivan commentedon Jan 17, 2018
Here is a test case for it that fails:
JukkaL commentedon Jan 26, 2018
The challenge here is that type aliases are completely replaced during semantic analysis, and thus we can't easily determine which type aliases were used after the fact. Here are two approaches for resolving this:
The first approach would likely require pretty major changes to mypy, since each
Typeobject might need to be dereferenced to get the actual effective type. I prefer the second approach due to its simplicity, though it's a little hacky.ilevkivskyi commentedon Jan 26, 2018
There is a related issue #4082, but I think these two are independent. The other issue is about having it clear in the symbol table (not via
type_overrideand other hacks), but the question about what to do about expanded types is different. I agree that option 2 is a bit hacky, but we did conceptually similar thing for forward references and it seems to work well. So I am fine with option 2 (also it is easy to implement).Support type aliases in fine-grained incremental mode (#4525)
Support type aliases in fine-grained incremental mode (python#4525)