Search code examples
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:

  • autopep8 1.3.4
  • VSCode 1.23.1

Solution

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

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

    Hope this can still help someone!