Skip to content

Error accessing named tuple defined within import cycle #3054

Description

@JukkaL

Mypy doesn't recognize access to a named tuple defined in another module within an import cycle, if the other module is processed later than the module that contains the reference to the named tuple.

Example:

# a.py
from collections import namedtuple
from b import f
N = namedtuple('N', 'a')
# b.py
import a
def f(x: a.N) -> None: ...  # Invalid type "a.N"

A potential fix is to process references to types in a later phase of semantic analysis than type definitions.

This is related to #3016.

Activity

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