Skip to content

Recursive type definition produces unexpected error message #7125

Closed

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.

Activity

  1. AlexWaygood commented on Jun 18, 2022

    @AlexWaygood
    Member

    The error message is now slightly different, but still seems bad:

    tmp/other.pyi:2: error: Module "lib" has no attribute "A"
    
  2. ilevkivskyi commented on Aug 23, 2022

    @ilevkivskyi
    Member

    I don't think this is relevant anymore, the test passes with --enable-recursive-aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions