-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
false-positivemypy gave an error on correct codemypy gave an error on correct codefeaturepriority-0-high
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).
Evpok, aperiodic, jordangarside, Jongy, DanielShaulov and 21 more
Metadata
Metadata
Assignees
Labels
false-positivemypy gave an error on correct codemypy gave an error on correct codefeaturepriority-0-high