Closed
Description
Obviously, this example is infinitely recursive. The original code that produced the error was more complicated so I distilled it down to the simplest example that still triggers the error.
from typing import Union, NamedTuple
class Foo(NamedTuple):
bar: Union[Foo, bool]
def make_foo() -> Union[Foo, bool]:
return Foo(make_foo())
# foo.py:7: error: Incompatible return value type (got "Foo", expected "Union[Foo, bool]")
Replacing the body of make_foo
with the following does not get rid of the error, but produces an extra error which may or may not be unrelated.
bar: Union[Foo, bool] = make_foo()
return Foo(bar)
# foo.py:7: error: Incompatible types in assignment (expression has type "Union[Foo, bool]", variable has type "Union[Foo, bool]")
# foo.py:8: error: Incompatible return value type (got "Foo", expected "Union[Foo, bool]")````
Metadata
Metadata
Assignees
Labels
No labels