While working on a conversion project, I noticed that certain files would throw KeyError's for \N{...} strings.
A minimal test case looks like:
world = "world"
print("hello {} \N{snowman}".format(world))
Which I would expect to be left alone or rewritten as:
world = "world"
print(f"hello {world} \N{snowman}")
I had trouble reproducing it in pytests. This seemed to trigger the same error:
diff --git tests/fstrings_test.py tests/fstrings_test.py
index d850293..a772a0f 100644
--- tests/fstrings_test.py
+++ tests/fstrings_test.py
@@ -48,6 +48,7 @@ def test_fix_fstrings_noop(s):
('"hello {}!".format(name)', 'f"hello {name}!"'),
('"{}{{}}{}".format(escaped, y)', 'f"{escaped}{{}}{y}"'),
('"{}{b}{}".format(a, c, b=b)', 'f"{a}{b}{c}"'),
+ (r'"{}\N{snowman}".format(a)', r'f"{a}\N{snowman}"'),
# TODO: poor man's f-strings?
# '"{foo}".format(**locals())'
),
While working on a conversion project, I noticed that certain files would throw
KeyError's for\N{...}strings.A minimal test case looks like:
Which I would expect to be left alone or rewritten as:
I had trouble reproducing it in pytests. This seemed to trigger the same error: