How to avoid python autopep8 formatting in a line in VSCode?
Asked Answered
F

1

19

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
Flowerer answered 14/6, 2018 at 11:7 Comment(1)
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.Chukar
M
33

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!

Methylamine answered 11/9, 2019 at 16:45 Comment(3)
Is it possible for autopep8 to create a bug? I have noticed that it can be agressive moving imported libraries, etc.Systematist
It's not working for me. It's still formatting it. Any ideas for debugging why?Stative
It's not working for autopep8 vscode extensionRoper

© 2022 - 2024 — McMap. All rights reserved.