VS Code > Preferences > User Settings > Extensions > Python > Linting > Flake8 Args Added Item stopped working
Asked Answered
C

5

9

Please don't treat this as an "asked and answered" question. I sincerely have been clobbering to try to figure out why this has stopped working, if it's a VS Code problem, or a Flake8 one, or if I'm just crazy and should find another way around this.

Looking for a way to stop the Flake8 linter's "file is too long" and "not used" warnings, I found a solution listed as one of the hottest on StackFlow. I copied and pasted it exactly and it worked! Great, but while following Django Project tutorial on this code in admin.py file:

from django.contrib import admin
from .models import Choice, Question


class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 3


class QuestionAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['question_text']}),
        ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
    ]
    inlines = [ChoiceInline]


admin.site.register(Question, QuestionAdmin)

suddenly, (the setting had been working fine for days), I got this Problem warning: line too long(80 > 79 characters) flake8(E501) (13,80)

I know I may be too picky on this but it is really annoying. I've also read that I can break the line up using a backslash without breaking the continuity of the code, but I also tried that and got a message saying that the backslash is redundant within brackets.

I went back to the settings and checked that they're still exactly as the Args suggested that had in fact worked. I removed the changes. I closed and re-started VS Code, went back and reinserted the settings again. Still getting the same error and I don't know from where Flake8 is getting and reproducing the error message with the 80 being greater than 79 information.

Does anyone have an idea of why the settings just suddenly stopped working and flake8 reverted back to ignoring the arguments it was directed to ignore in the settings?

This was the hot solution that stopped working for me: VS Code, Preferences, User Settings, Extensions, Python, Linting, Flake8 Args

"python.linting.flake8Args": [
    "--max-line-length=120",
    "--ignore=E402,F841,F401,E302,E305",
],

I even tried extending the line length to 180 and adding E501 to the ignore list. Nothing works.

Cardiomegaly answered 21/11, 2019 at 15:7 Comment(0)
A
11

Change flake8 settings in the settings.json file, use "flake8.args": as opposed to the original "python.linting.flake8Args":.

This was changed September of 2023 due to VSCode migrating to separate Python tools.

Agretha answered 15/12, 2022 at 4:31 Comment(1)
Yes. You right! =DLeafstalk
S
6

What worked for me was adding the args into the Graphical UI instead of settings.json.

enter image description here

Segmental answered 18/9, 2022 at 19:30 Comment(0)
C
3

This is an edit to finding my own answer. I found that if I make the suggested edits in the actual settings.json file instead of through the VS Code User Settings interface, the edit actually does work.

I'm not sure if I can say that just changing it there alone is sufficient because in my research and searches I hit upon installing flake in the virtual environment folder. I thought that would be a good idea anyway because I didn't want vscode to be using a global system installed flake8, which I'm assuming happens when you install the vscode flake8 extension.

So, I first used pip to install flake8 in my virtual environment project folder. I checked with pip freeze. Flake8 is located in the Windows \Scripts folder of the virtual environment.

Then I located the settings.json file in the .vscode folder in that virtual environment project folder.

Everything I had done before, didn't work. and I tried a lot of the other suggestions on StackOverflow. As I read through the Flake8 documentation I hit on writing a setup.cfg file but no matter where I placed it, I wasn't getting the results of ignoring the warnings and errors I wanted.

Then I went back and re-read the original suggestion and noticed it mentioned two ways of doing this, and I tried editing the settings.json file. If anyone can add explanation, I'd still appreciate it, but as far as I'm concerned, I have found a satisfactory answer. It's been a great learning experience.

Cardiomegaly answered 21/11, 2019 at 22:48 Comment(1)
Yes, this solution worked. I also had multiple settings.json, added E501 ignore code to settings.json in .vscode dir worked.Mangan
S
3

I know this is a bit of an old question and Leslie Alldridge's answer is correct, but I'd like to add this for completeness. There are a few resources online that direct you to set this under "python.linting.flake8Args", and it seems the OP was doing it that way. Perhaps that worked in the past and something was changed in Flake8 that broke it, but it doesn't seem to work anymore. For me it only works if you put the setting in "flake8.args".

Subserve answered 6/11, 2022 at 21:58 Comment(0)
D
1

I also had this problem and the solution in my case was to disable "pycodestyleEnabled":

{
"python.linting.pycodestyleEnabled": false
}
Doughboy answered 6/12, 2019 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.