Skip to content

Commit 792ac76

Browse files
Simplify return type inference to use master type map only
1 parent 91a3b0b commit 792ac76

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

mypy/checker.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,15 +1618,13 @@ def is_unannotated_any(t: Type) -> bool:
16181618
and not self.dynamic_funcs[-1]
16191619
):
16201620
# Collect return types from return statements
1621-
# Merge types from all type maps to get complete picture
1622-
all_return_types: list[Type] = []
1623-
for type_map in self._type_maps:
1624-
return_types_list = get_return_types(type_map, item)
1625-
all_return_types.extend(return_types_list)
1621+
# Use the master type map (first in stack) where final types are stored
1622+
# At this point in type checking, return statement types should be in the master map
1623+
return_types_list = get_return_types(self._type_maps[0], item)
16261624

1627-
if all_return_types:
1625+
if return_types_list:
16281626
# Create union of all return types
1629-
inferred_ret_type = make_simplified_union(all_return_types)
1627+
inferred_ret_type = make_simplified_union(return_types_list)
16301628
# Update the function's return type
16311629
typ = typ.copy_modified(ret_type=inferred_ret_type)
16321630
item.type = typ

0 commit comments

Comments
 (0)