False positive Type alias cannot refer to itself indirectly in its definition
when using dataclasses, NamedTuple or NewType
#4770
Labels
addressed in next version
Issue is fixed and will appear in next published version
bug
Something isn't working
Describe the bug
I'm getting a false positive
Type alias ... cannot refer to itself indirectly in its definition
error on a type alias whose definition refers to a dataclass (or typing.NamedTuple or Newtype).The exact same line of code triggered #4596 about a month ago, but that one was fixed in 1.1.294 released about a day after I stumbled into it so I just updated and it went away. Now reappeared after minor changes to the types involved.
Screenshots or Code
Which gives me the error:
Type alias "AnAlias" cannot refer to itself indirectly in its definition (reportGeneralTypeIssues)
.VS Code extension or command-line
Running 1.1.298, with or without
strict
. Pyright finds no other problems with the code.Additional context
In the the repro below the alias is a union, but in the original code it was a Callable, neither works.
Replacing the dataclass with an equivalent hand-crafted class makes it work, other commented out examples break.
The alias needs to be "used" before the class is defined, but there's no need to make a value of the alias type before it's fully defined like the
f(0)
above. This also triggers it:The text was updated successfully, but these errors were encountered: