Skip to content

Commit

Permalink
Replace a nested for loop with a product() call
Browse files Browse the repository at this point in the history
  • Loading branch information
PCManticore committed Oct 11, 2018
1 parent cd33ae2 commit ca20c86
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions astroid/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,25 +752,18 @@ def _infer_binop(self, context):
context = context or contextmod.InferenceContext()
lhs_context = contextmod.copy_context(context)
rhs_context = contextmod.copy_context(context)

for lhs in left.infer(context=lhs_context):
if lhs is util.Uninferable:
lhs_iter = left.infer(context=lhs_context)
rhs_iter = right.infer(context=rhs_context)
for lhs, rhs in itertools.product(lhs_iter, rhs_iter):
if any(value is util.Uninferable for value in (rhs, lhs)):
# Don't know how to process this.
yield util.Uninferable
return

for rhs in right.infer(context=rhs_context):
if rhs is util.Uninferable:
# Don't know how to process this.
yield util.Uninferable
return

try:
yield from _infer_binary_operation(
lhs, rhs, self, context, _get_binop_flow
)
except exceptions._NonDeducibleTypeHierarchy:
yield util.Uninferable
try:
yield from _infer_binary_operation(lhs, rhs, self, context, _get_binop_flow)
except exceptions._NonDeducibleTypeHierarchy:
yield util.Uninferable


@decorators.yes_if_nothing_inferred
Expand Down

0 comments on commit ca20c86

Please sign in to comment.