black: Black fail to format long strings and comments
Black https://github.com/python/black/commit/9ed254
Options
--line-length=88
Input
very_long_string = "123456789123456789E123456789asgfpjaspogjojasfogjoajfgojaofjgpaojfgdfkksdkhgspkgpk/k"
# Cordoba, Spain (CNN)The fortress town of Zahara de la Sierra in southern Spain is used to fending off enemies. The Moors and Christians fought over it in medieval times, and it was sacked by the French in 1812. Now its formidable position high above the Andalusian countryside has suddenly become an invaluable asset once more.
# On March 14, Zahara cut itself off from the outside world as a dangerous coronavirus spread its tentacles across Spain. The mayor, 40-year-old Santiago Galván, decided to block all but one of the town's five entrances. Galván acted the day that Spain's "state of alarm" came into force.
Output
very_long_string = "123456789123456789E123456789asgfpjaspogjojasfogjoajfgojaofjgpaojfgdfkksdkhgspkgpk/k"
# Cordoba, Spain (CNN)The fortress town of Zahara de la Sierra in southern Spain is used to fending off enemies. The Moors and Christians fought over it in medieval times, and it was sacked by the French in 1812. Now its formidable position high above the Andalusian countryside has suddenly become an invaluable asset once more.
# On March 14, Zahara cut itself off from the outside world as a dangerous coronavirus spread its tentacles across Spain. The mayor, 40-year-old Santiago Galván, decided to block all but one of the town's five entrances. Galván acted the day that Spain's "state of alarm" came into force.
Expected
Output
very_long_string = (
"123456789123456789E123456789asgfpjaspogjojasfogjoajfg"
"ojaofjgpaojfgdfkksdkhgspkgpk/k")
# Cordoba, Spain (CNN)The fortress town of Zahara de la Sierra in southern
# Spain is used to fending off enemies. The Moors and Christians fought over it
# in medieval times, and it was sacked by the French in 1812. Now its
# formidable position high above the Andalusian countryside has suddenly become
# an invaluable asset once more.
# On March 14, Zahara cut itself off from the outside world as a dangerous
# coronavirus spread its tentacles across Spain. The mayor, 40-year-old
# Santiago Galván, decided to block all but one of the town's five entrances.
# Galván acted the day that Spain's "state of alarm" came into force.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 18
- Comments: 15 (1 by maintainers)
The
--previewflag will format long strings but not long comments. There are no current plans to split long comments.git has loads of experimental features, they are still mentioned in the cli docs. How else are people supposed to try them so you can receive more testing + feedback 😃
From Version 24.1.0,
--preview --enable-unstable-feature string_processing@neoglez It should be noted that #1132 will not change the output of the example that you gave above since the example string has no spaces in it. This would be undesirable, for example, in the case of long URLs.
Do you plan to strip comment line also ? Flake is raising error, Black doesn’t allow us to solve them.
With the latest version of black (22.1) this is now enabled by using the
--previewflag on black: https://black.readthedocs.io/en/stable/change_log.html#highlightsClosing since 1) the
--experimental-string-processingflag has landed which handles the string part of this issue, 2) making it the default is tracked separated in https://github.com/psf/black/issues/2188, and 3) the comments case in tracked specifically in https://github.com/psf/black/issues/1713.Thanks for the suggestions, at least one of them got accepted 😃