Skip to content

Recursive type definition produces unexpected error message #7125

Closed
@JukkaL

Description

@JukkaL

This test cases produces unexpected output:

[case testRecursiveNamedTupleTypedDict2]
# flags: --new-semantic-analyzer
import a
[file a.py]
import lib
x: int
[file a.py.2]
import lib
x: lib.A
reveal_type(x.x['x'])
[file lib.pyi]
from typing import NamedTuple
from other import B
A = NamedTuple('A', [('x', B)])
[file other.pyi]
from mypy_extensions import TypedDict
from lib import A
B = TypedDict('B', {'x': A})
[builtins fixtures/dict.pyi]

Here's the output:

tmp/lib.pyi:2: error: Module 'other' has no attribute 'B'

I'd expect there to be an error about a cyclic definition instead.

There is an existing test case testRecursiveNamedTupleTypedDict in check-incremental.test that triggers the error. The above test case is slightly simplified version of that test case.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions