Skip to content

Do not call is_subtype and is_same_type in third pass of semantic analysis #3977

Closed

Description

@ilevkivskyi

We recently eliminated calls to join from semantic analysis and postponed them to callbacks before type checking. However, third pass still calls is_subtype and is_same_type. I think this can cause problems, and it is better to refactor these calls to a later stage (probably also to the callbacks).

This was discovered while working on #3952

Activity

  1. carljm commented on Dec 20, 2017

    @carljm
    Member

    We are seeing a crash due to this issue, when (accidentally) using a module in a Union inside a container type. Repro code is:

    import datetime
    from typing import List, Union
    
    x: List[Union[int, datetime]] = []
    
    x.append(1)
    

    Obviously the code intends to use datetime.datetime instead of datetime, but it should not cause a crash. Remove either the Union or the List and we instead see the expected "invalid type" error.

    Posting here because the backtrace passes through https://github.com/python/mypy/blob/master/mypy/subtypes.py#L81 via semantic analyzer pass 3, so this is the root cause. Let me know if you want a dedicated issue for this crash and I will create one.

    Not pasting full traceback since it's easily reproducible with the above code sample.

  2. carljm commented on Dec 20, 2017

    @carljm
    Member

    #4384 fixes this crash.

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

    priority-1-normalrefactoring

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions