'Python: Black doesn't wrap long lines
I am using black==20.8b1
.
I have a long string like:
return f"{self.name}, a {adjective.to_name()} {kin_string}{self._type.to_name()} who works for the {target.get_relationship_target_string()}."
I run:
$ black -l 80 . -t py38
All done! ✨ 🍰 ✨
2 files left unchanged.
Why is the string not wrapped? I thought that black
supports wrapping strings now (based on issues in github).
Solution 1:[1]
Currently we have to add --experimental-string-processing
tag to it. I think in future versions it will be made default.
black -l 80 --experimental-string-processing file.py
Solution 2:[2]
Currently, Black doesn't wrap long strings or long comments. You can see an open issue in their project GitHub saying:
Black currently doesn't wrap long string literals or merge string literals that happen to be on the same line. [...] It would require modifying the AST which isn't 100% safe and has a bunch of edge cases to be dealt with.
Solution 3:[3]
Since 22.1.0, you have to run Black with --preview
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vinzee |
Solution 2 | |
Solution 3 | GG. |