Skip to content

Commit

Permalink
Review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 28, 2023
1 parent 3a1b0dd commit 4fb738d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@ def const_infer_binary_op(
def _multiply_seq_by_int(
self: _TupleListNodeT,
opnode: nodes.AugAssign | nodes.BinOp,
other: nodes.Const,
value: int,
context: InferenceContext,
) -> _TupleListNodeT:
node = self.__class__(parent=opnode)
if isinstance(other.value, int) and other.value > 1e8:
if value > 1e8:
node.elts = [util.Uninferable]
return node
filtered_elts = (
helpers.safe_infer(elt, context) or util.Uninferable
for elt in self.elts
if not isinstance(elt, util.UninferableBase)
)
node.elts = list(filtered_elts) * other.value
node.elts = list(filtered_elts) * value
return node


Expand Down Expand Up @@ -224,14 +224,17 @@ def tl_infer_binary_op(
if not isinstance(other.value, int):
yield not_implemented
return
yield _multiply_seq_by_int(self, opnode, other, context)
yield _multiply_seq_by_int(self, opnode, other.value, context)
elif isinstance(other, bases.Instance) and operator == "*":
# Verify if the instance supports __index__.
as_index = helpers.class_instance_as_index(other)
if not as_index:
yield util.Uninferable
elif not isinstance(as_index.value, int):
# already checked by class_instance_as_index() but faster than casting
raise AssertionError("Please open a bug report.")
else:
yield _multiply_seq_by_int(self, opnode, as_index, context)
yield _multiply_seq_by_int(self, opnode, as_index.value, context)
else:
yield not_implemented

Expand Down

0 comments on commit 4fb738d

Please sign in to comment.