File tree 3 files changed +25
-1
lines changed 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ What's New in astroid 4.0.0?
7
7
============================
8
8
Release date: TBA
9
9
10
+ * Fix crashes with large positive and negative list multipliers.
11
+
12
+ Closes #2521
13
+ Closes #2523
10
14
11
15
12
16
What's New in astroid 3.3.5?
Original file line number Diff line number Diff line change @@ -142,7 +142,10 @@ def _multiply_seq_by_int(
142
142
context : InferenceContext ,
143
143
) -> _TupleListNodeT :
144
144
node = self .__class__ (parent = opnode )
145
- if value > 1e8 :
145
+ if value <= 0 :
146
+ node .elts = []
147
+ return node
148
+ if len (self .elts ) * value > 1e8 :
146
149
node .elts = [util .Uninferable ]
147
150
return node
148
151
filtered_elts = (
Original file line number Diff line number Diff line change @@ -286,6 +286,23 @@ def test_uninferable_list_multiplication() -> None:
286
286
element = parsed .inferred ()[0 ].elts [0 ]
287
287
assert element .value is Uninferable
288
288
289
+ @staticmethod
290
+ def test_uninferable_list_multiplication_with_multiple_operands () -> None :
291
+ """Attempting to calculate the result is prohibitively expensive."""
292
+ parsed = extract_node ("[0] * 825 * 16547118" )
293
+ element = parsed .inferred ()[0 ].elts [0 ]
294
+ assert element .value is Uninferable
295
+
296
+ @staticmethod
297
+ def test_list_multiplication_with_zero_multiplier () -> None :
298
+ parsed = extract_node ("[0] * 0" )
299
+ assert parsed .inferred ()[0 ].elts == []
300
+
301
+ @staticmethod
302
+ def test_list_multiplication_with_negative_multiplier () -> None :
303
+ parsed = extract_node ("[0] * -9223372036854775809" )
304
+ assert parsed .inferred ()[0 ].elts == []
305
+
289
306
290
307
def test_named_expr_inference () -> None :
291
308
code = """
You can’t perform that action at this time.
0 commit comments