Skip to content

Commit 42144f9

Browse files
h-joocopybara-github
authored andcommitted
Avoid checking types of Callable when both type objects are pointing to the same reference. This is a small check which would speed up cases drastically such as recursive generics with unions, since the type is equal but Pytype holds the expanded union type and attempts to go in deep to figure out each individual type matches.
PiperOrigin-RevId: 700376520
1 parent 97d9491 commit 42144f9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pytype/matcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,11 @@ def _match_callable_args_against_callable(
15501550
):
15511551
# TODO(mdemello): Unify with _match_signature_args_against_callable()
15521552
param_match = self._get_param_matcher(other_type)
1553+
# Checking type against the same type should happen quite often. This check
1554+
# helps avoiding near-infinite type expansion for recursive generic types
1555+
# which are identical.
1556+
if left is other_type:
1557+
return subst
15531558
for i in range(left.num_args):
15541559
left_arg = left.formal_type_parameters[i]
15551560
right_arg = other_type.formal_type_parameters[i]

0 commit comments

Comments
 (0)