Search code examples
pythonvisual-studio-codepep8autoformattingautoformat

My VS Code doesn't respect PEP8 line limit on auto formatting


I already enabled autopep8 extension and It shows rendering on bottom of my VS Code when I save the file, but It doesn't respect the line wrap in PEP8 not matter how big It is. How can I enable word wrap?

Here's my settings.json:

{
    "files.trimTrailingWhitespace": true,
    "python.formatting.provider": "yapf",
    "editor.formatOnSave": true,

    "[python]": {
        "editor.rulers": [90]
    },
}

Code example:

translated_msg = self.string_parser.receive_a_string_with_or_without_tokens_and_return_it_with_the_proper_values(final_msg)

Sorry the long name method, It's not my fault

Shouldn't be at least this?

translated_msg = self.string_parser.receive_a_string_with_or_without_tokens_and_return_it_with_the_proper_values(
    final_msg
)

Solution

  • Two things. One, your settings are set to use yapf, not autopep8 but your question mentions the latter. So are you using yapf or autopep8?

    Two, you can specify the line length either via a configuration file or a command-line flag through "python.formatting.autopep8Args". See the autopep8 docs on how to specify the line length.