Skip to content

Add a flag indicating use of (unsupported) unicode surrogates - #82

Merged
ilevkivskyi merged 3 commits into
mainfrom
fix-surrogate
Sep 4, 2026
Merged

Add a flag indicating use of (unsupported) unicode surrogates#82
ilevkivskyi merged 3 commits into
mainfrom
fix-surrogate

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Collaborator

Ruff parser doesn't preserve Unicode surrogate codepoints, see astral-sh/ruff#13666, and it looks like there are no plans to add any support soon. For now we simply mark these, so that we can flag them as not supported in mypyc (as mypy itself doesn't really care about string literal contents).

Note that I don't set the flag for individual "fragments" of f-string and t-strings, only on the string as a whole (to save some space and simplify logic).

@ilevkivskyi

Copy link
Copy Markdown
Collaborator Author

Here is the mypy counterpart python/mypy#21936

@JukkaL JukkaL 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! It would be nice to have some unit tests for this functionality.

@ilevkivskyi

Copy link
Copy Markdown
Collaborator Author

@JukkaL OK, I added tests, and while doing so I learned that Rust strings can't have raw (unpaired) surrogates. Trying to read such from file will fail, as this is not a valid UTF-8. Also, unlike in Python, "\u{d800}" is a syntax error in Rust. Not sure what happens when we read a file in Python and try to pass it to Rust via pyo3, so I decided to be defensive just in case.

@ilevkivskyi
ilevkivskyi merged commit 3c54841 into main Sep 4, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the fix-surrogate branch September 4, 2026 14:16
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