17

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
Juan Antonio
  • 2,451
  • 3
  • 24
  • 34
  • There's no way to have VS Code be the one to do what you want. Basically it looks like a bug in autopep8 since that shouldn't be an issue assuming the rest of the file is syntactically correct. You might want to consider using Black as your formatter instead. – Brett Cannon Jun 14 '18 at 19:28

1 Answers1

27

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!

EmlJnke
  • 394
  • 4
  • 5
  • Is it possible for `autopep8` to create a bug? I have noticed that it can be agressive moving imported libraries, etc. – C-3PO May 11 '22 at 17:04
  • 1
    It's not working for me. It's still formatting it. Any ideas for debugging why? – Mote Zart Aug 05 '22 at 18:18