Rewrite format literals containing \N escapes#281
Closed
gvangool wants to merge 9 commits intoasottile:masterfrom
Closed
Rewrite format literals containing \N escapes#281gvangool wants to merge 9 commits intoasottile:masterfrom
gvangool wants to merge 9 commits intoasottile:masterfrom
Conversation
asottile
reviewed
Apr 12, 2020
Owner
asottile
left a comment
There was a problem hiding this comment.
just a couple edge cases -- definitely works for the cases you've proposed though 👍
asottile
reviewed
Apr 13, 2020
asottile
reviewed
Apr 13, 2020
asottile
reviewed
Apr 13, 2020
Owner
|
looks good, looks like there's one last thing to fix 🤔 diff --git a/tests/format_literals_test.py b/tests/format_literals_test.py
index f3610a1..a809f74 100644
--- a/tests/format_literals_test.py
+++ b/tests/format_literals_test.py
@@ -49,7 +49,7 @@ def test_intentionally_not_round_trip(s, expected):
"'{' '0}'.format(1)",
# comment looks like placeholder but is not!
'("{0}" # {1}\n"{2}").format(1, 2, 3)',
- # TODO: this works by accident (extended escape treated as placeholder)
+ # this works by accident (extended escape treated as placeholder)
r'"\N{snowman} {}".format(1)',
),
)
@@ -99,6 +99,8 @@ def test_format_literals_noop(s):
),
# parenthesized string literals
('("{0}").format(1)', '("{}").format(1)'),
+ # extended unicode escapes
+ (r'"\N{snowman} {0}".format(1)', r'"\N{snowman} {}".format(1)'),
),
)
def test_format_literals(s, expected): |
asottile
reviewed
Apr 18, 2020
gvangool
commented
Apr 25, 2020
Comment on lines
+2450
to
+2454
| try: | ||
| tokens[i] = token._replace(src=_to_fstring(token.src, node)) | ||
| del tokens[i + 1:end + 1] | ||
| except KeyError: | ||
| pass |
Author
There was a problem hiding this comment.
I was looking for an unparse-like function that could be used in the _to_fstring because this feels like it's handling an implementation detail.
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.
This is my attempt at fixing #280 (I started it for #278).
It's based on current parser behaviour:
%encoding we let it convert to\N{{snowman}}and fix it afterwards.format, the source will end with\N(with name beingsnowman). We can reuse the original format for this.