21

I am learning flask and building a app based on Corey Schafer's Youtube tutorials. I'm using VS-Code as my editor of choice.

In tutorial 5 he splits his app into a package structure and when I do it I run into a problem. In my settings I enabled the "editor.formatOnSave": true and the formatter I use is autopep8. Now when I move one of my import statements from the top to the bottom of my file and save, the formatter moves it back to the top. I'm guessing its because of 'E402 - Fix module level import not at top of file'?

I tried to ignore it with the "python.formatting.autopep8Args": [--ignore=E402] but that did nothing. Maybe here you can only turn of lynting errors and E402 is only a lynting error and its not relevant for the formatting?

I hope you can help me disable or fix it.

Cheers

ueberBrot
  • 431
  • 3
  • 10
  • 21
    I don't know `autopep8` well, but that example is mis-formatted as you're missing quotes around the argument: `"python.formatting.autopep8Args": ["--ignore=E402"]`. – Brett Cannon Dec 03 '18 at 21:57
  • 4
    For future readers this might help : https://stackoverflow.com/a/54016555/5753035. – Pramesh Bajracharya Apr 05 '19 at 06:25
  • @BrettCannon reading the link from Pramesh, you can even improve the right side of the setting: the arguments for the formatter should be passed as separate list items in quotes like ["--ignore","E402"] rather than [--ignore=E402] – Timo Jan 01 '21 at 10:20
  • 1
    @Timo they are equivalent, so you can choose whichever format you prefer as it makes no difference to autopep8. – Brett Cannon Jan 08 '21 at 18:22

1 Answers1

11

Brett Cannon comment:

I don't know autopep8 well, but that example is mis-formatted as you're missing quotes around the argument: "python.formatting.autopep8Args": ["--ignore=E402"]

@BrettCannon terrific! That fixed it. Tried so long to fix it that i forgot those quotes and didnt see that they were missing.

LightCC
  • 9,804
  • 5
  • 52
  • 92
ueberBrot
  • 431
  • 3
  • 10