Repository navigation
MPT-24937 Express the item-count guard as \d with re.ASCII - #417
Conversation
SonarCloud flagged the character class on the MPT-Item-Count guard: "Use concise character class syntax '\d' instead of '[0-9]'". The literal substitution the rule suggests is wrong here, because Python's re module is Unicode-aware by default: a bare \d matches U+0665, U+06F5 and U+FF15, so it would re-admit exactly the non-ASCII digits this guard exists to reject. Pass re.ASCII alongside \d, which restores the [0-9] semantics the guard needs and satisfies the rule. Verified equivalent: as written the guard rejects U+0665, and dropping the flag makes it accept the same header as 5 again, so the existing non-ASCII rejection test is the regression guard for the flag. The comment now says why re.ASCII is load-bearing, so it is not simplified away later. No behaviour change. Refs MPT-24937. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📜 Recent review details🧰 Additional context used📓 Path-based instructions (1)For each subsequent commit in this PR, explicitly verify if previous review comments have been resolved⚙️ CodeRabbit configuration file Files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughThe streaming mixin now defines ChangesStreaming item count parsing
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to Item-count validation now uses the concise digit expression while continuing to reject non-ASCII digits, with no identified behavior or merge-readiness risk. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
Comment |
|



🤖 AI-generated PR — Please review carefully.
Follow-up to #414 (merged), answering @albertsola's review question on that PR: "any reason to ignore sonarcloud?" — there was a reason, and this lands the version that satisfies Sonar without losing it.
What
SonarCloud raised a warning-level annotation on the guard added in #414:
The annotation sits on the
SonarCloud Code Analysischeck run rather than in the PR comments, which is why it was easy to miss while the quality gate itself passed.Applying the rule literally would have reintroduced the bug MPT-24937 fixed. Python's
reis Unicode-aware by default, so a bare\dmatches Unicode decimal digits — exactly the inputs the guard exists to reject:[0-9]+\d+\d++re.ASCII10٥U+0665 arabic-indic five۵U+06F5 extended-arabic five5U+FF15 fullwidth fiveint("٥")is5, so a bare\dwould have restored the original defect: a garbled header silently normalized into a wrong count.How
Pass
re.ASCIIalongside\d, which restores exactly the[0-9]semantics the guard needs and satisfies the rule:The comment above it now records why the flag is load-bearing, so a later "simplification" does not quietly drop it.
Testing
test_declared_item_count_rejects_int_formsalready asserts that U+0665 is rejected, so it is the regression guard for the flag.declared_item_count:ruff format,ruff check,flake8,mypy(205 files) anduv lock --checkpass; 2646 unit tests pass at 99% coverage.No behaviour change: this is
[0-9]+and\d+/re.ASCIIbeing the same matcher, chosen so the static-analysis rule is satisfied rather than suppressed.🤖 Generated with Claude Code
Closes MPT-24937
ITEM_COUNT_PATTERNto use\d+withre.ASCII.re.ASCIIis required.