Closed
Description
I am not sure if this is a bug or intended behaviour but I have problems when using type aliases as class members. This is the code I thought should work:
from typing import NamedTuple
class A:
Alias = NamedTuple("Alias", [("field", str)])
def f(self, x: Alias) -> str: return x.field
class B:
Alias = A.Alias
def f(self, x: Alias) -> str: return x.field
gives the following errors:
mypy_alias.py:9: error: Variable "mypy_alias.B.Alias" is not valid as a type
mypy_alias.py:9: error: Alias? has no attribute "field"
I noticed this simpler code also does not work, I am not sure if it is connected?
class A:
Alias = str
def f(self, x: Alias) -> str: return x
This gives: mypy_alias.py:3: error: Variable "mypy_alias.A.Alias" is not valid as a type
I am using python 3.6.9 and mypy 0.730
Metadata
Metadata
Assignees
Labels
No labels