Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OverflowError with empty list and large multiplier #2597

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading