Skip to content

Refresh of partial type produces the wrong type in fine-grained incremental mode #4464

Closed

Description

@JukkaL

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.

Activity

  1. JukkaL commented on Jan 19, 2018

    @JukkaL
    CollaboratorAuthor

    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.
  2. self-assigned this
    on Feb 5, 2018
  3. JukkaL commented on Mar 12, 2018

    @JukkaL
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions