Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Dataflow analysis #313

Closed
Closed

Description

@lostmsu
a = None
if condition():
  a = True
else:
  a = False
a

Desired: analysis of a in the last line should only return bool
Actual: it returns bool and None

That's a huge feature request, mostly for tracking purposes.

Activity

  1. MikhailArkhipov commented on Jun 3, 2019

    @MikhailArkhipov

    New LS no longer collects combinations of types. In the example above a will be just bool.

  2. lostmsu commented on Jun 3, 2019

    @lostmsu
    ContributorAuthor

    Mikhail Arkhipov (@MikhailArkhipov) out of curiosity: what would the new LS say about a in

    if condition():
      a = "1"
    else:
      a = [1]
  3. jakebailey commented on Jun 3, 2019

    @jakebailey
    Member

    In that example, list, because we take the final assign:

    image

    You couldn't represent that code within the python typing world.

    However, we do handle something like this:

    image

  4. lostmsu commented on Jun 3, 2019

    @lostmsu
    ContributorAuthor

    Jake Bailey (@jakebailey) why not? What is the difference between b and a in this case? Why can't a be Union[str, list]?

  5. jakebailey commented on Jun 3, 2019

    @jakebailey
    Member

    I overstated; you're right, we could potentially merge those multiple assigns (without dataflow analysis). The returns work because we can find every type returned and do the union then (which is less complicated).

  6. lostmsu commented on Jun 3, 2019

    @lostmsu
    ContributorAuthor

    Jake Bailey (@jakebailey) the older analysis would collect types from both branches. So that later it could strengthen the union as in Union[XDerivedFromBase, YDerivedFromBase] -> Base. Is this now completely ignored within a single function body?

  7. jakebailey commented on Jun 3, 2019

    @jakebailey
    Member

    Currently, the new analysis doesn't do any sort of unioning or strengthening at all, other than the return type case I gave above. You can specify the type using a type annotation (so, say that something is Base explicitly), but we currently don't do anything special to handle multiple assignments over variables besides normal scoping rules.

  8. MikhailArkhipov commented on Jun 3, 2019

    @MikhailArkhipov

    Analysis no longer collects unions of possible combinations of values for performance and memory consumption reasons. Similarly, it no longer collects or stores all possible function return types with various arguments.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions