Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Python Formatting: Change max line-length with autopep8 / yapf / black

I am experimenting with different python formatters and would like to increase the max line length. Ideally without editing the settings.json file. Is there a way to achieve that? select formatter

like image 299
tkazik Avatar asked Sep 06 '25 13:09

tkazik


2 Answers

For all three formatters, the max line length can be increased with additional arguments passed in from settings, i.e.:

  • autopep8 args: --max-line-length=120
  • black args: --line-length=120
  • yapf args: --style={based_on_style: google, column_limit: 120, indent_width: 4}

Hope that helps someone in the future!

enter image description here

like image 162
tkazik Avatar answered Sep 08 '25 03:09

tkazik


@tkazik answered his own question correctly, however, I thought it would be helpful to include some references:

VSCode documentation on using Python formatters:
https://code.visualstudio.com/docs/python/editing#_formatting

autopep8 command line options:
https://pypi.org/project/autopep8/#usage

  • Note that there is also an option to point the formatter to a global config file
  • Additionally, if you have a local or global config file in the expected location, these preferences will be used automatically by the formatter in VSCode (https://pypi.org/project/autopep8/#configuration)

black command line options:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#command-line-options

yapf command line options:
https://github.com/google/yapf#usage

like image 28
karski Avatar answered Sep 08 '25 02:09

karski