Skip to content

MPT-24937 Express the item-count guard as \d with re.ASCII - #417

Merged
jentyk merged 1 commit into
mainfrom
bugfix/MPT-24937/item-count-guard-ascii-flag
Sep 8, 2026
Merged

jentyk merged 1 commit into
mainfrom
bugfix/MPT-24937/item-count-guard-ascii-flag

Conversation

@jentyk

@jentyk jentyk commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

🤖 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:

mpt_api_client/http/mixins/streaming_mixin.py:45  (warning)
Use concise character class syntax '\d' instead of '[0-9]'.

The annotation sits on the SonarCloud Code Analysis check 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 re is Unicode-aware by default, so a bare \d matches Unicode decimal digits — exactly the inputs the guard exists to reject:

header value [0-9]+ \d+ \d+ + re.ASCII
10 ✅ accept ✅ accept ✅ accept
٥ U+0665 arabic-indic five ❌ reject ✅ accept ❌ reject
۵ U+06F5 extended-arabic five ❌ reject ✅ accept ❌ reject
5 U+FF15 fullwidth five ❌ reject ✅ accept ❌ reject

int("٥") is 5, so a bare \d would have restored the original defect: a garbled header silently normalized into a wrong count.

How

Pass re.ASCII alongside \d, which restores exactly the [0-9] semantics the guard needs and satisfies the rule:

ITEM_COUNT_PATTERN = re.compile(r"\d+", re.ASCII)

The comment above it now records why the flag is load-bearing, so a later "simplification" does not quietly drop it.

Testing

  • No new tests. test_declared_item_count_rejects_int_forms already asserts that U+0665 is rejected, so it is the regression guard for the flag.
  • Verified the flag is load-bearing by swapping the pattern at runtime against the real declared_item_count:
as shipped (\d+, re.ASCII)  -> raised ItemCountMissing   (correct)
re.ASCII removed            -> returned 5                (bug returns)
previous [0-9]+ form        -> raised ItemCountMissing   (correct)
  • ruff format, ruff check, flake8, mypy (205 files) and uv lock --check pass; 2646 unit tests pass at 99% coverage.

No behaviour change: this is [0-9]+ and \d+/re.ASCII being the same matcher, chosen so the static-analysis rule is satisfied rather than suppressed.

🤖 Generated with Claude Code

Closes MPT-24937

  • Update ITEM_COUNT_PATTERN to use \d+ with re.ASCII.
  • Preserve ASCII-only digit matching.
  • Document why re.ASCII is required.

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>
@jentyk
jentyk requested a review from a team as a code owner September 8, 2026 10:49
@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

✅ Found Jira issue key in the title: MPT-24937

Generated by 🚫 dangerJS against 23eccfe

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 1fcbcda0-4a89-4001-ba84-a8fc034f0e27

📥 Commits

Reviewing files that changed from the base of the PR and between 8289580 and 23eccfe.

📒 Files selected for processing (1)
  • mpt_api_client/http/mixins/streaming_mixin.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • softwareone-platform/mpt-extension-skills (manual)

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:

  • mpt_api_client/http/mixins/streaming_mixin.py
🔇 Additional comments (1)
mpt_api_client/http/mixins/streaming_mixin.py (1)

42-47: LGTM!


📝 Walkthrough

Walkthrough

The streaming mixin now defines ITEM_COUNT_PATTERN with \d+ and re.ASCII. The comment explains why the flag prevents matching non-ASCII digits. The accepted character set remains unchanged.

Changes

Streaming item count parsing

Layer / File(s) Summary
ASCII item count pattern
mpt_api_client/http/mixins/streaming_mixin.py
ITEM_COUNT_PATTERN uses \d+ with re.ASCII. The comment documents the Unicode behavior of \d and the purpose of the flag.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 23ecc

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)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Documentation Up To Date ✅ Passed PASS: This PR is a behavior-preserving refactor. The only changed file is streaming_mixin.py; [0-9]+ and \\d+ with re.ASCII match the same ASCII-only strings, including rejection of Unicode dig…

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

@jentyk
jentyk merged commit b29806c into main Sep 8, 2026
7 checks passed
@jentyk
jentyk deleted the bugfix/MPT-24937/item-count-guard-ascii-flag branch September 8, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants