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
Refresh of partial type produces the wrong type in fine-grained incremental mode #4464
This test case fails in fine-grained incremental mode, though the code is okay in batch mode:
[case testRefreshPartialSpanningScopes]
import a
a.x
class A:
x = None
def f(self) -> None:
a.x
self.x = '' # Incompatible types in assignment (expression has type "str",
# variable has type "None")
[file a.py]
x = 0
[file a.py.2]
x = ''
The type of attribute A.x is derived from information in two scopes (class body and method f), and this logic fails in fine-grained incremental mode.
The best fix might be to require an annotation for x in class body.
Here is a vague idea about solving this without altering mypy semantics:
Introduce the concept of "bound targets". If a set of some targets are bound, each time one of the targets in the set becomes stale, also process all other targets in this set at the same time. This is subtly different from fine-grained dependencies, where the triggered targets are processed in a separate propagation step.
During dependency generation, if we notice a partial type that spans two targets, bind the two targets. Thus they will both be processed together. This actually isn't sufficient as a fix but it might help -- it looks like in the original example both targets actually become stale at the same time, but things still go wrong. We'll need to update deferred processing to support partial types, which might be a bit messy.
If two targets are bound, they can never become unbound until server restart, for simplicity. Binding targets when not necessary should be harmless, and it should only incur some (very) minor performance overhead.
This works now (annotation is consistently required for x). We removed support for partial types spanning multiple scopes in fine-grained incremental mode a while ago.
Activity
JukkaL commentedon Jan 19, 2018
Here is a vague idea about solving this without altering mypy semantics:
JukkaL commentedon Mar 12, 2018
This works now (annotation is consistently required for
x). We removed support for partial types spanning multiple scopes in fine-grained incremental mode a while ago.