@@ -6957,10 +6957,6 @@ def narrow_type_by_identity_equality(
69576957 def propagate_up_typemap_info (self , new_types : TypeMap ) -> TypeMap :
69586958 """Attempts refining parent expressions of any MemberExpr or IndexExprs in new_types.
69596959
6960- Specifically, this function accepts two mappings of expression to original types:
6961- the original mapping (existing_types), and a new mapping (new_types) intended to
6962- update the original.
6963-
69646960 This function iterates through new_types and attempts to use the information to try
69656961 refining any parent types that happen to be unions.
69666962
@@ -6979,23 +6975,12 @@ def propagate_up_typemap_info(self, new_types: TypeMap) -> TypeMap:
69796975
69806976 We return the newly refined map. This map is guaranteed to be a superset of 'new_types'.
69816977 """
6982- output_map = {}
6978+ all_mappings = [ new_types ]
69836979 for expr , expr_type in new_types .items ():
6984- # The original inferred type should always be present in the output map, of course
6985- output_map [expr ] = expr_type
6986-
6987- # Next, try using this information to refine the parent types, if applicable.
6988- new_mapping = self .refine_parent_types (expr , expr_type )
6989- for parent_expr , proposed_parent_type in new_mapping .items ():
6990- # We don't try inferring anything if we've already inferred something for
6991- # the parent expression.
6992- # TODO: Consider picking the narrower type instead of always discarding this?
6993- if parent_expr in new_types :
6994- continue
6995- output_map [parent_expr ] = proposed_parent_type
6996- return output_map
6980+ all_mappings .append (self .refine_parent_types (expr , expr_type ))
6981+ return reduce_and_conditional_type_maps (all_mappings , use_meet = True )
69976982
6998- def refine_parent_types (self , expr : Expression , expr_type : Type ) -> Mapping [ Expression , Type ] :
6983+ def refine_parent_types (self , expr : Expression , expr_type : Type ) -> TypeMap :
69996984 """Checks if the given expr is a 'lookup operation' into a union and iteratively refines
70006985 the parent types based on the 'expr_type'.
70016986
@@ -8744,6 +8729,8 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty
87448729 return ms [0 ]
87458730 result = ms [0 ]
87468731 for m in ms [1 :]:
8732+ if not m :
8733+ continue # this is a micro-optimisation
87478734 result = and_conditional_maps (result , m , use_meet = use_meet )
87488735 return result
87498736
0 commit comments