pythonformattingvisual-studio-codeautopep8

How to avoid python autopep8 formatting in a line in VSCode?


I have a problem with the name of a var in a python file, using VSCode and autopep8, this is an example:

...
formal_education: bool
...

Autopep formater change the format like this:

...
formal_education: 
   bool
...

Raising a SyntaxError detected by flake8, so, I have tried special comments like: # autopep8: noqa and others using some specific PEPs but seems like the editor skip some phase previous to and seem imposible to avoid this behaviour.

I know that the problem is about for word inside of var name.

A solution for now is disable the format check in save stage "editor.formatOnSave": false, but I would like to know how to solve this, maybe some config to autopep or maybe directly over VSCode, or how to apply special comments directly in the file to achieve this goal.

Thanks!

I am using:


Solution

  • Although this is old, here's a solution:

    Just put # nopep8 at the end of the line(s) that shouldn't be formatted.

    For a broader disabling of any formatters, # noqa can be used. (No Quality Assurance)

    Hope this can still help someone!