File tree 3 files changed +40
-8
lines changed
3 files changed +40
-8
lines changed Original file line number Diff line number Diff line change @@ -4550,17 +4550,16 @@ def has_no_custom_eq_checks(t: Type) -> bool:
4550
4550
self ._check_for_truthy_type (original_vartype , node )
4551
4551
vartype = try_expanding_sum_type_to_union (original_vartype , "builtins.bool" )
4552
4552
4553
- if_type = true_only (vartype ) # type: Type
4554
- else_type = false_only (vartype ) # type: Type
4555
- ref = node # type: Expression
4553
+ if_type = true_only (vartype )
4554
+ else_type = false_only (vartype )
4556
4555
if_map = (
4557
- {ref : if_type }
4558
- if not isinstance (get_proper_type ( if_type ) , UninhabitedType )
4556
+ {node : if_type }
4557
+ if not isinstance (if_type , UninhabitedType )
4559
4558
else None
4560
4559
)
4561
4560
else_map = (
4562
- {ref : else_type }
4563
- if not isinstance (get_proper_type ( else_type ) , UninhabitedType )
4561
+ {node : else_type }
4562
+ if not isinstance (else_type , UninhabitedType )
4564
4563
else None
4565
4564
)
4566
4565
return if_map , else_map
Original file line number Diff line number Diff line change @@ -723,7 +723,10 @@ class Status(Enum):
723
723
typ = get_proper_type (typ )
724
724
725
725
if isinstance (typ , UnionType ):
726
- items = [try_expanding_sum_type_to_union (item , target_fullname ) for item in typ .items ]
726
+ items = [
727
+ try_expanding_sum_type_to_union (item , target_fullname )
728
+ for item in typ .relevant_items ()
729
+ ]
727
730
return make_simplified_union (items , contract_literals = False )
728
731
elif isinstance (typ , Instance ) and typ .type .fullname == target_fullname :
729
732
if typ .type .is_enum :
Original file line number Diff line number Diff line change @@ -3210,3 +3210,33 @@ def test(seq: List[Union[Iterable, Any]]) -> None:
3210
3210
k = [k]
3211
3211
reveal_type(k) # N: Revealed type is "builtins.list[Any]"
3212
3212
[builtins fixtures/list.pyi]
3213
+
3214
+ [case testRegression11705_Strict]
3215
+ # flags: --strict-optional
3216
+ # See: https://github.com/python/mypy/issues/11705
3217
+ from typing import Dict, Optional, NamedTuple
3218
+ class C(NamedTuple):
3219
+ x: int
3220
+
3221
+ t: Optional[C]
3222
+ d: Dict[C, bytes]
3223
+ x = t and d[t]
3224
+ reveal_type(x) # N: Revealed type is "Union[None, builtins.bytes*]"
3225
+ if x:
3226
+ reveal_type(x) # N: Revealed type is "builtins.bytes*"
3227
+ [builtins fixtures/dict.pyi]
3228
+
3229
+ [case testRegression11705_NoStrict]
3230
+ # flags: --no-strict-optional
3231
+ # See: https://github.com/python/mypy/issues/11705
3232
+ from typing import Dict, Optional, NamedTuple
3233
+ class C(NamedTuple):
3234
+ x: int
3235
+
3236
+ t: Optional[C]
3237
+ d: Dict[C, bytes]
3238
+ x = t and d[t]
3239
+ reveal_type(x) # N: Revealed type is "builtins.bytes*"
3240
+ if x:
3241
+ reveal_type(x) # N: Revealed type is "builtins.bytes*"
3242
+ [builtins fixtures/dict.pyi]
You can’t perform that action at this time.
0 commit comments