Skip to content

Commit

Permalink
Fix OverflowError with empty list and large multiplier
Browse files Browse the repository at this point in the history
This regressed in dfe1ccc.
  • Loading branch information
correctmost authored and DanielNoord committed Oct 2, 2024
1 parent dfe1ccc commit d174ca2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _multiply_seq_by_int(
context: InferenceContext,
) -> _TupleListNodeT:
node = self.__class__(parent=opnode)
if value <= 0:
if value <= 0 or not self.elts:
node.elts = []
return node
if len(self.elts) * value > 1e8:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,18 @@ def test_uninferable_list_multiplication_with_multiple_operands() -> None:
element = parsed.inferred()[0].elts[0]
assert element.value is Uninferable

@staticmethod
def test_list_multiplication_with_empty_list_and_overflowing_multiplier() -> None:
parsed = extract_node("[] * 1163845194457646539560")
assert parsed.inferred()[0].elts == []

@staticmethod
def test_list_multiplication_with_zero_multiplier() -> None:
parsed = extract_node("[0] * 0")
assert parsed.inferred()[0].elts == []

@staticmethod
def test_list_multiplication_with_negative_multiplier() -> None:
def test_list_multiplication_with_negative_overflowing_multiplier() -> None:
parsed = extract_node("[0] * -9223372036854775809")
assert parsed.inferred()[0].elts == []

Expand Down

0 comments on commit d174ca2

Please sign in to comment.