#3855·black

string_processing: Error when re-flowing implicitly concatenated r-strings

Author: FeuermurmelCreated Aug 27, 2023Updated Sep 24, 2026
LabelsT: bugF: stringsC: preview style

Describe the bug

Trying to format the following input (playground) with black -l 1 --preview leads to an error:

python
dict(a=r' ' r'')
$ black -l 1 --preview foo.py 
error: cannot format foo.py: Cannot parse: 5:4:     r""

Oh no!   
1 file failed to reformat.

Some additional variants that lead to the same error:

python
dict(a=r' ' '')
dict(a=r' ' " ")

The error does not appear if --preview is not used. The file is formatted correctly in that case.

Environment

  • Black's version: 23.7.0 (compiled: yes)
  • OS and Python version: Python 3.8.18 on macOS 12.6.8 (Apple Silicon)

Also fails in the playground using the current main version (see above).