Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

f-strings not formatted correctly on python 3.12 #22

Open
johncarter-phntm opened this issue Mar 13, 2024 · 0 comments
Open

f-strings not formatted correctly on python 3.12 #22

johncarter-phntm opened this issue Mar 13, 2024 · 0 comments

Comments

@johncarter-phntm
Copy link

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"
?  ^    ^


----------------------------------------------------------------------
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant