Skip to content

Have multiple passes by SemanticAnalyzerPass3 to resolve more forward references. #4095

Closed

Description

@ilevkivskyi

As mentioned in #3952 (comment) some double-forward references (and other corner cases) are currently not resolved. For example this does not work:

x: A
A = B
B = List[int]

This is because third pass happens only once. In checker.py we have deferred nodes, and there are mini-passes over them until they are all done, I think we can adopt the same idea here and have repeated third passes.

This is however low priority since these edge cases are extremely rare and don't cause crashes, only false positives.

Activity

  1. ilevkivskyi commented on Oct 10, 2017

    @ilevkivskyi
    MemberAuthor

    Related #731

  2. gvanrossum commented on Oct 10, 2017

    @gvanrossum
    Member

    Also that particular example won't work -- even if you protect the x: A from crashing (e.g. using x: 'A'), A = B will still crash.

  3. ilevkivskyi commented on Oct 10, 2017

    @ilevkivskyi
    MemberAuthor

    Yes, this is just a simple illustration, there are other more complex situations that will work at runtime, but not in mypy, all of them are purely "academic" however.

  4. ilevkivskyi commented on Oct 10, 2017

    @ilevkivskyi
    MemberAuthor

    Even this one formally speaking can be protected by if TYPE_CHECKING: ...

  5. ilevkivskyi commented on Nov 7, 2019

    @ilevkivskyi
    MemberAuthor

    This now works correctly with the new analyzer.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions