Skip to content

"Invalid type" when using type alias in import cycle #4498

Closed

Description

@JukkaL

Type checking the following files results in an unexpected "Invalid type" error:

t.py:

MYPY = False
if MYPY:
    from t2 import A

x: A  # Invalid type "t2.A"   <---- unexpected

t2.py:

import t
from typing import Callable

A = Callable[[], None]

The reason for the error is that t and t2 form an import cycle and t is processed before t2 in the cycle, and thus the type alias A hasn't been processed when we analyze t.

This is probably the same bug as #4442, but for users this may not be obvious, so it perhaps makes maintain a separate issue.

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions