Skip to content

Commit

Permalink
Avoid checking types of Callable when both type objects are pointing …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
h-joo authored and copybara-github committed Nov 26, 2024
1 parent 97d9491 commit 42144f9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pytype/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,11 @@ def _match_callable_args_against_callable(
):
# TODO(mdemello): Unify with _match_signature_args_against_callable()
param_match = self._get_param_matcher(other_type)
# Checking type against the same type should happen quite often. This check
# helps avoiding near-infinite type expansion for recursive generic types
# which are identical.
if left is other_type:
return subst
for i in range(left.num_args):
left_arg = left.formal_type_parameters[i]
right_arg = other_type.formal_type_parameters[i]
Expand Down

0 comments on commit 42144f9

Please sign in to comment.