Skip to content

Type aliases are not recognized correctly in some situations with import cycles #5130

Closed
@dfroger

Description

@dfroger

This may be a duplicate issue, but I'm a bit lost... I'm using mypy 0.600 and Python 3.6.2.

# a.py
from typing import Union

from c import T

class A:
    x: str

class B:
    x: str

U = Union[A, B]
# b.py
from c import U

def foo(u: U):
    print(u.x)
# c.py
class T:
    pass

from a import U
from b import foo

python -c 'import c' works, Mypy . give the errors:

b.py:3: error: Invalid type "a.U"
b.py:4: error: U? has no attribute "x"

I would like to understand how here Mypy import mechanism is different from Python import mechanism, and why Mypy fails with U type.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions