File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -4702,14 +4702,20 @@ def conditional_len_map(self,
4702
4702
possible_types = union_items (current_type )
4703
4703
len_of_types = [len_of_type (typ ) for typ in possible_types ]
4704
4704
4705
- proposed_type = UnionType ([
4705
+ proposed_type = make_simplified_union ([
4706
4706
self .narrow_type_by_length (typ , length )
4707
4707
for typ , l in zip (possible_types , len_of_types )
4708
4708
if l is None or l == length ])
4709
- remaining_type = UnionType ([
4709
+ remaining_type = make_simplified_union ([
4710
4710
typ for typ , l in zip (possible_types , len_of_types )
4711
4711
if l is None or l != length ])
4712
- return {expr : proposed_type }, {expr : remaining_type }
4712
+ if_map = (
4713
+ {} if is_same_type (proposed_type , current_type )
4714
+ else {expr : proposed_type })
4715
+ else_map = (
4716
+ {} if is_same_type (remaining_type , current_type )
4717
+ else {expr : remaining_type })
4718
+ return if_map , else_map
4713
4719
else :
4714
4720
return {}, {}
4715
4721
Original file line number Diff line number Diff line change @@ -1078,8 +1078,8 @@ else:
1078
1078
reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int, builtins.int]"
1079
1079
[builtins fixtures/len.pyi]
1080
1080
1081
- [case testNarrowingLenListAndStrUnaffected ]
1082
- from typing import Tuple, Union, List
1081
+ [case testNarrowingLenTypeUnaffected ]
1082
+ from typing import Tuple, Union, List, Any
1083
1083
1084
1084
def make() -> Union[str, List[int]]:
1085
1085
return ""
@@ -1090,6 +1090,13 @@ if len(x) == 3:
1090
1090
reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.list[builtins.int]]"
1091
1091
else:
1092
1092
reveal_type(x) # N: Revealed type is "Union[builtins.str, builtins.list[builtins.int]]"
1093
+
1094
+ def f(self, value: Any) -> Any:
1095
+ if isinstance(value, list) and len(value) == 0:
1096
+ reveal_type(value) # N: Revealed type is "builtins.list[Any]"
1097
+ return value
1098
+ reveal_type(value) # N: Revealed type is "Any"
1099
+ return None
1093
1100
[builtins fixtures/len.pyi]
1094
1101
1095
1102
[case testNarrowingLenLiteral]
You can’t perform that action at this time.
0 commit comments