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.
fromtypingimportUnion, NamedTupleclassFoo(NamedTuple):
bar: Union[Foo, bool]
defmake_foo() ->Union[Foo, bool]:
returnFoo(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()
returnFoo(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]")````
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.
Replacing the body of
make_foowith the following does not get rid of the error, but produces an extra error which may or may not be unrelated.