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):
iffoo():
x=0# Type of x is 'int' hereelse:
x=''# No error here# Type of x is 'str' herereveal_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).
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):Currently the second assignment generates an error, and the type of
xisinteverywhere.This is a generalization of #6232 and related to #1174 (but not a direct follow-up issue).