0

How to instruct autopep8 python formatter to remove line breaks if the resulting line after removing the line breaks does not exceed the maximum allowed line length? For example, I have the following code that was previously formatted with --max-line-length 80:

def function(a, b, c):
    pass


function('VERYLOOOOOOOOOOOOONGSTRING',
         'VERYLOOOOOOOOOOOOONGSTRING', 'VERYLOOOOOOOOOOOOONGSTRING')

Now maximum line length is 120. I want autopep8 -i --max-line-length 120 test.py to format it like this:

def function(a, b, c):
    pass


function('VERYLOOOOOOOOOOOOONGSTRING', 'VERYLOOOOOOOOOOOOONGSTRING', 'VERYLOOOOOOOOOOOOONGSTRING')

But it does not remove line breaks. Adding multiple --aggressive options does not help either.

If it's not possible do to with autopep8, what other formatters/software can I use to do it? Thanks in advance!

g00dds
  • 195
  • 8
  • I don't think `autopep8` has this feature, as PEP 8 doesn't concern itself with ensuring lines have *minimum* length. Recommendations for other tools is explicitly off-topic. – chepner Mar 31 '23 at 12:39
  • (this is going to be closed as "seeking recommendation for software tools", probably, and autopep8 doesn't support this) you may consider using other formatters like `black` (or it's fork `blue` with single quote preference) and `yapf`. – STerliakov Mar 31 '23 at 13:35

0 Answers0