Skip to content

cap oversized str/bytes and sequence concatenation during inference#3129

Open
kali834x wants to merge 2 commits into
pylint-dev:mainfrom
kali834x:concat-size-cap
Open

cap oversized str/bytes and sequence concatenation during inference#3129
kali834x wants to merge 2 commits into
pylint-dev:mainfrom
kali834x:concat-size-cap

Conversation

@kali834x

@kali834x kali834x commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Type of Changes

Type
🐛 Bug fix

Description

the repetition operators are size-capped in const_infer_binary_op (*, <<) and _multiply_seq_by_int (*), but concatenation with + is not, and each operand can sit just under the cap. ("a" * 90000000) + ("b" * 90000000) is 34 source characters yet materializes a 180 MB Const string during inference, and chaining more + terms grows it without bound. the list/tuple path in tl_infer_binary_op is worse: _filter_uninferable_nodes infers every element of the concatenated sequence, so ([0] * 90000000) + ([0] * 90000000) walks ~1.8e8 elements. both + branches now yield Uninferable once the combined length passes 1e8, the additive analog of the existing repetition guards. small concatenations keep inferring their exact value.

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing kali834x:concat-size-cap (b6c75d0) with main (faf2884)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.61%. Comparing base (fe29fb1) to head (b6c75d0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3129   +/-   ##
=======================================
  Coverage   93.61%   93.61%           
=======================================
  Files          92       92           
  Lines       11381    11387    +6     
=======================================
+ Hits        10654    10660    +6     
  Misses        727      727           
Flag Coverage Δ
linux 93.48% <100.00%> (+<0.01%) ⬆️
pypy 93.61% <100.00%> (+<0.01%) ⬆️
windows 93.58% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/protocols.py 91.29% <100.00%> (+0.11%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please shorten the comments, they read like AI generated text and are too detailed

Comment thread ChangeLog Outdated
Comment on lines +11 to +17
* Bound str/bytes and list/tuple concatenation (``a + b``) during inference.
The repetition operators (``*``, ``<<``, ``**``) are size-capped, but
concatenation was not, so two operands each just under the cap combine past
it and chaining ``+`` grows the result without bound. ``const_infer_binary_op``
and ``tl_infer_binary_op`` now infer ``Uninferable`` once the combined length
exceeds ``1e8``, matching the repetition guards. The list/tuple path also
inferred every element of the concatenated sequence before the fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Daniel this is way too verbose.

Suggested change
* Bound str/bytes and list/tuple concatenation (``a + b``) during inference.
The repetition operators (``*``, ``<<``, ``**``) are size-capped, but
concatenation was not, so two operands each just under the cap combine past
it and chaining ``+`` grows the result without bound. ``const_infer_binary_op``
and ``tl_infer_binary_op`` now infer ``Uninferable`` once the combined length
exceeds ``1e8``, matching the repetition guards. The list/tuple path also
inferred every element of the concatenated sequence before the fix.
* Bound str/bytes and list/tuple concatenation (``a + b``) during inference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, cut it down to the single line.

@kali834x

kali834x commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Trimmed the code comments and test docstrings down to one line each, and the changelog entry is now just the single line Pierre suggested.

@Pierre-Sassoulas Pierre-Sassoulas added the Blocked 🚧 A PR or issue blocked by another PR or issue label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Blocked 🚧 A PR or issue blocked by another PR or issue topic-performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants