Closed
Description
Maybe if a variable is initialized both in if and else blocks, the resulting type should be the union of the types of the initializers (only when using --allow-redefinitions
):
if foo():
x = 0
# Type of x is 'int' here
else:
x = '' # No error here
# Type of x is 'str' here
reveal_type(x) # Union[int, str]
Currently the second assignment generates an error, and the type of x
is int
everywhere.
This is a generalization of #6232 and related to #1174 (but not a direct follow-up issue).