From d174ca24bde0bba7df63f024124381efe908330d Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:45:43 -0400 Subject: [PATCH] Fix OverflowError with empty list and large multiplier This regressed in dfe1ccce8576. --- astroid/protocols.py | 2 +- tests/test_protocols.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/astroid/protocols.py b/astroid/protocols.py index 4688f74713..8a837b86b7 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -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: diff --git a/tests/test_protocols.py b/tests/test_protocols.py index f718fd1e9c..4a9f1f6022 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -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 == []