Skip to content

Commit d174ca2

Browse files
correctmostDanielNoord
authored andcommitted
Fix OverflowError with empty list and large multiplier
This regressed in dfe1ccc.
1 parent dfe1ccc commit d174ca2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

astroid/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _multiply_seq_by_int(
142142
context: InferenceContext,
143143
) -> _TupleListNodeT:
144144
node = self.__class__(parent=opnode)
145-
if value <= 0:
145+
if value <= 0 or not self.elts:
146146
node.elts = []
147147
return node
148148
if len(self.elts) * value > 1e8:

tests/test_protocols.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,18 @@ def test_uninferable_list_multiplication_with_multiple_operands() -> None:
293293
element = parsed.inferred()[0].elts[0]
294294
assert element.value is Uninferable
295295

296+
@staticmethod
297+
def test_list_multiplication_with_empty_list_and_overflowing_multiplier() -> None:
298+
parsed = extract_node("[] * 1163845194457646539560")
299+
assert parsed.inferred()[0].elts == []
300+
296301
@staticmethod
297302
def test_list_multiplication_with_zero_multiplier() -> None:
298303
parsed = extract_node("[0] * 0")
299304
assert parsed.inferred()[0].elts == []
300305

301306
@staticmethod
302-
def test_list_multiplication_with_negative_multiplier() -> None:
307+
def test_list_multiplication_with_negative_overflowing_multiplier() -> None:
303308
parsed = extract_node("[0] * -9223372036854775809")
304309
assert parsed.inferred()[0].elts == []
305310

0 commit comments

Comments
 (0)