Skip to content

"Can't determine type" error in import cycles with named tuples and typed dicts #5658

Closed
@ilevkivskyi

Description

@ilevkivskyi

Consider this test case which currently fails with Cannot determine type of "tp":

[case testNamedTupleImportCycle]
import b
[file a.py]
class C:
    pass

from b import tp
reveal_type(tp)  # Cannot determine type of 'tp'
tp('x')  # Cannot determine type of 'tp'

[file b.py]
from a import C
from typing import NamedTuple

tp = NamedTuple('tp', [('x', int)])
[out]

Note however that such code will anyway fail at runtime, and it works if one imports under if MYPY: (see #2015). I think therefore it is relatively low priority.

This is a follow up for #5635

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions