Repository navigation
Preserve lone surrogates in Python AST constants - #10159
Merged
youknowone merged 1 commit intoDec 4, 2026
Merged
Conversation
Retain exact values for surrogate-bearing constants in the node metadata used for AST input. Use the original values for code generation and mapping patterns, and do not rewrite percent formats when the generated literal would be lossy. Refs: RustPython#9852 Assisted-by: Codex:GPT-6.2
Contributor
|
Caution Review failedThe pull request is closed.
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. |
youknowone
marked this pull request as ready for review
December 4, 2026 02:16
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
youknowone
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CPython's Python-to-AST bridge retains the original object for
Constant.value. RustPython's bridge otherwise passes a lone surrogate through Ruff's UTF-8-only representation and reads it back as U+FFFD. This can change returned strings and nested tuple/frozenset values, or make two distinct mapping-pattern keys look identical.Keep the original value in the existing AST node-identity metadata only for constants that cannot fit in Ruff's string representation. This leaves ordinary parse input, AST round-trip metadata, source positions, Ruff, and Lib unchanged. The percent-format preprocessor keeps the original modulo operation rather than building a lossy literal; full optimized AST shape parity for surrogate formats is separate. The intermediate constants in f- and t-strings keep their values too. The error type for a surrogate used as an integer format code and docstring cleanup are out of scope.
Linux verification: 132 differential observations against CPython 3.15.2 (35 mismatches corrected; 7 remain as noted above, no previously matching result changed), 340 selected canonical cases (one CPython-only skip on RustPython), 799 codegen unit tests, and the newly added snippet section. The new snippet fails on the same main build and passes on both CPython and the candidate. Full hosted platforms, full test suites and performance are not verified locally.
Refs #9852.