Skip to content

Fix octal escapes in re module - #934

Merged
davidhewitt merged 2 commits into
pydantic:mainfrom
Rogdham:re-escape-octal
Oct 5, 2026
Merged

davidhewitt merged 2 commits into
pydantic:mainfrom
Rogdham:re-escape-octal

Conversation

@Rogdham

@Rogdham Rogdham commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

In the re module, fix the handling of specific cases of \number as explained in CPython documentation:

If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number.

Three-digit octal escapes above 0o377 (255) raise PatternError like CPython does. Getting the position right in the error message was the difficult part.

AI disclosure: LLMs have been used to detect the issue and help prepare this PR.


Summary by cubic

Fixes octal escape handling in re replacement templates so \0 and three-digit octal escapes like \123 are translated as characters, and escapes above 0o377 raise PatternError with the correct position. Validation now also runs when a negative count skips substitution, matching CPython.

Written for commit 076168f. Summary will update on new commits.

Review in cubic

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/monty/src/modules/re.rs 66.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 45 untouched benchmarks
⏩ 16 skipped benchmarks1


Comparing Rogdham:re-escape-octal (076168f) with main (985071a)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Rogdham
Rogdham marked this pull request as ready for review September 24, 2026 18:37

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread crates/monty/src/types/re_pattern.rs Resolved
Comment thread crates/monty/src/types/re_pattern.rs Resolved

@davidhewitt davidhewitt left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks

@davidhewitt
davidhewitt merged commit 7de608b into pydantic:main Oct 5, 2026
44 checks passed
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