Add a flag indicating use of (unsupported) unicode surrogates - #82
Merged
Conversation
Collaborator
Author
|
Here is the mypy counterpart python/mypy#21936 |
JukkaL
approved these changes
Sep 4, 2026
JukkaL
left a comment
Contributor
There was a problem hiding this comment.
Thanks! It would be nice to have some unit tests for this functionality.
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, |
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.
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).