Skip to content

Generated classes does not work with forward references #1701

Closed
@MeGotsThis

Description

@MeGotsThis

It seems mypy has trouble with generated classes such as NamedTuple.

a.py:

import b
from typing import Any, NamedTuple

class A:
    def a(self, b: 'b.B') -> str:
        return 'a'

ATuple = NamedTuple('ATuple', [('a', Any)])

b.py:

import a

class B:
    def b(self, a: 'a.A') -> str:
        return 'b'

    def aWithTuple(self, atuple: 'a.ATuple') -> str:
        return 'a'

mypy a.py output

a.py:1: note: In module imported here:
b.py: note: In function "aWithTuple":
b.py:7: error: Invalid type "a.ATuple"

mypy b.py works just fine

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions