Skip to content

Support type aliases in fine-grained incremental mode #4394

Closed

Description

@JukkaL

This includes generic type aliases such as X = Dict[str, T] and aliases to all kinds of types.

Generating dependencies may be tricky.

Activity

  1. msullivan commented on Jan 17, 2018

    @msullivan
    Collaborator

    Here is a test case for it that fails:

    [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]
    ==
    
  2. JukkaL commented on Jan 26, 2018

    @JukkaL
    CollaboratorAuthor

    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:

    1. Create a new type for type alias references that doesn't get simplified away during semantic analysis.
    2. 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.

  3. ilevkivskyi commented on Jan 26, 2018

    @ilevkivskyi
    Member

    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).

  4. self-assigned this
    on Jan 26, 2018
  5. added a commit that references this issue on Feb 21, 2018
    8f253c2
  6. added a commit that references this issue on Mar 15, 2018
    5600ae8
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