String += concatenation inside a loop
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.
What it detects
A variable is rebuilt with += inside a for/while loop and the appended value looks like a string (contains a quote), so this is likely the classic result = '' ; for ...: result += ... antipattern. Python strings are immutable, so each += allocates a new string, making the loop O(n^2) in the total length. Heuristic: it cannot fully distinguish string accumulation from numeric accumulation, so a quote in the appended value is required. ''.join(parts) (building a list, then joining once) is linear.
Why it matters
Python strings are immutable, so result += piece inside a loop allocates a brand-new string and copies the old contents into it on every single iteration, making the total work O(n^2) in the final string's length instead of O(n). On a short loop this is invisible; building up a large string this way (a report, a large CSV, a big HTML blob) can turn into a real, measurable slowdown as the loop grows. This detector requires the appended value to contain a quote to avoid flagging numeric accumulators like total += price, but it cannot fully distinguish every case.
How to fix it
Collect the pieces in a list as you loop (parts.append(piece)) and build the final string once with ''.join(parts) after the loop. join is linear in the total length because it allocates the result string exactly once.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo