unify
unify copied to clipboard
f-strings not formatted correctly on python 3.12
It seems that f-strings aren't being correctly handled on python 3.12
For example, with this file:
#!/usr/bin/env python
somedict = {"somekey": "example value"}
print(f"{somedict['somekey']}")
This command:
unify example.py --check-only --quote '"'
Produces these invalid changes:
@@ -3,4 +3,4 @@
somedict = {"somekey": "example value"}
-print(f"{somedict['somekey']}")
+print(f"{somedict["somekey"]}")
Note that the tests are also failing (passing with 3.11):
======================================================================
FAIL: test_format_code (test_unify.TestUnitsWithFstrings.test_format_code)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/johnc/Projects/unify/test_unify.py", line 91, in test_format_code
self.assertEqual("x = f'abc' \\\nf'next'\n",
AssertionError: "x = f'abc' \\\nf'next'\n" != 'x = f"abc" \\\nf"next"\n'
- x = f'abc' \
? ^ ^
+ x = f"abc" \
? ^ ^
- f'next'
? ^ ^
+ f"next"
? ^ ^
======================================================================
FAIL: test_format_code_with_backslash_in_comment (test_unify.TestUnitsWithFstrings.test_format_code_with_backslash_in_comment)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/johnc/Projects/unify/test_unify.py", line 96, in test_format_code_with_backslash_in_comment
self.assertEqual("x = f'abc' #\\\nf'next'\n",
AssertionError: "x = f'abc' #\\\nf'next'\n" != 'x = f"abc" #\\\nf"next"\n'
- x = f'abc' #\
? ^ ^
+ x = f"abc" #\
? ^ ^
- f'next'
? ^ ^
+ f"next"
? ^ ^
----------------------------------------------------------------------