@@ -4271,7 +4271,9 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
42714271 ):
42724272 self .msg .unreachable_right_operand (e .op , e .right )
42734273
4274- right_type = self .analyze_cond_branch (right_map , e .right , expanded_left_type )
4274+ right_type = self .analyze_cond_branch (
4275+ right_map , e .right , self ._combined_context (expanded_left_type )
4276+ )
42754277
42764278 if left_map is None and right_map is None :
42774279 return UninhabitedType ()
@@ -5879,26 +5881,26 @@ def analyze_cond_branch(
58795881 allow_none_return : bool = False ,
58805882 suppress_unreachable_errors : bool = True ,
58815883 ) -> Type :
5882- ctx_items = []
5883- if context is not None :
5884- ctx_items .append (context )
5885- if self .type_context and self .type_context [- 1 ] is not None :
5886- ctx_items .append (self .type_context [- 1 ])
5887- ctx : Type | None
5888- if ctx_items :
5889- ctx = make_simplified_union (ctx_items )
5890- else :
5891- ctx = None
58925884 with self .chk .binder .frame_context (can_skip = True , fall_through = 0 ):
58935885 if map is None :
58945886 # We still need to type check node, in case we want to
58955887 # process it for isinstance checks later. Since the branch was
58965888 # determined to be unreachable, any errors should be suppressed.
58975889 with self .msg .filter_errors (filter_errors = suppress_unreachable_errors ):
5898- self .accept (node , type_context = ctx , allow_none_return = allow_none_return )
5890+ self .accept (node , type_context = context , allow_none_return = allow_none_return )
58995891 return UninhabitedType ()
59005892 self .chk .push_type_map (map )
5901- return self .accept (node , type_context = ctx , allow_none_return = allow_none_return )
5893+ return self .accept (node , type_context = context , allow_none_return = allow_none_return )
5894+
5895+ def _combined_context (self , ty : Type | None ) -> Type | None :
5896+ ctx_items = []
5897+ if ty is not None :
5898+ ctx_items .append (ty )
5899+ if self .type_context and self .type_context [- 1 ] is not None :
5900+ ctx_items .append (self .type_context [- 1 ])
5901+ if ctx_items :
5902+ return make_simplified_union (ctx_items )
5903+ return None
59025904
59035905 #
59045906 # Helpers
0 commit comments