Skip to content

Normalize source newlines before warnings, compilation and diagnostics - #9793

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/pr9762-source-newlines
Nov 11, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/pr9762-source-newlines

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Normalize CRLF and lone CR before parser warnings and compilation, including physical newlines inside string literals. This follows CPython 3.15's _PyTokenizer_translate_newlines / _PyTokenizer_FromUTF8 ordering.

This is an independent alternative to close #9762, not stacked on it. The original change fixes literal values but runs after VM parser warnings and leaves diagnostics reading the untranslated input.

  • Share one universal-newline translator between source decoding, compiler entry points, symbol-table compilation, and syntax diagnostics.
  • Translate before VM parser warning collection. Keep diagnostic line lookup consistent with the translated parser source.
  • Borrow CR-free input; otherwise use a single output allocation instead of chained full-string replacements.
  • Preserve the caller's original source bytes in compile audit events.
  • Cover CR/CRLF combinations, ordinary/raw/bytes/f-/t-string literals, docstrings, explicit escape preservation, AST compilation, warnings, error text consistency and audit input.

Verification

  • CPython 3.15.1 and RustPython builtin_compile.py / builtin_compile_module.py: pytest 4 passed.
  • RustPython test_compile: passed (187 tests run, 51 skipped).
  • CLI -c physical-CR literal checks: passed.
  • Full workspace Rust tests, separate CAPI tests, workspace/CAPI clippy with -D warnings: passed.
  • Shared normalizer tests and pre-commit hooks: passed.

This does not claim full parser diagnostic parity: existing LF-input differences in trailing newlines in SyntaxError.text and warning-as-error precedence for invalid source also remain for CR input. This patch makes the newline forms consistent; it does not hide those independent differences.

AI assistance: OpenAI Codex.

…tion

Share universal-newline translation across byte decoding, compiler entry points and syntax diagnostics. Keep LF-only input borrowed and preserve original compile audit bytes. Cover literal values, docstrings, warnings and diagnostic consistency.

Assisted-by: OpenAI Codex:GPT-6.1
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Assisted-by: OpenAI Codex:GPT-6.1
@youknowone
youknowone marked this pull request as ready for review November 11, 2026 02:36
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-11T02:36:32.681578Z
We couldn’t complete this review. Comment @codex review to try again.
b658c0a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 5bfbb3b into RustPython:main Nov 11, 2026
28 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