Skip to content

Commit

Permalink
Allow backslashes in pep701 f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Jan 13, 2024
1 parent 34e4ede commit 8492be8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5,078 deletions.
1 change: 1 addition & 0 deletions src/python_minifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def unparse(module):
try:
compare_ast(module, minified_module)
except CompareError as compare_error:
print(printer.code)
raise UnstableMinification(compare_error, '', printer.code)

return printer.code
Expand Down
6 changes: 4 additions & 2 deletions src/python_minifier/f_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def _literals(self):
l += '\\n'
elif c == '\r':
l += '\\r'
elif c == '\\':
l += '\\\\'
else:
l += c

Expand All @@ -301,8 +303,8 @@ def __str__(self):
if self._s == '':
return str(min(self.allowed_quotes, key=len)) * 2

if '\0' in self._s or '\\' in self._s:
raise ValueError('Impossible to represent a %r character in f-string expression part')
if '\0' in self._s or ('\\' in self._s and not self.pep701):
raise ValueError('Impossible to represent a character in f-string expression part')

if not self.pep701 and ('\n' in self._s or '\r' in self._s):
if '"""' not in self.allowed_quotes and "'''" not in self.allowed_quotes:
Expand Down
Loading

0 comments on commit 8492be8

Please sign in to comment.