skip to Main Content

I’m using VS Code with Flake8 configured to check some obvious issues for my Python code. However, some of its errors are not really errors in my current development phase, e.g. E501 (line too long) and F401 (unused import).

The annoying thing is that the relevant lines are marked in red, which makes more serious errors non-obvious.

Is there a way I can tell Flake8 to treat them as warnings instead of errors?

I searched all over, but only discovered ways to either ignore the check all together, or explicitly mark one line as ignored, e.g. How to tell flake8 to ignore comments. They are not what I need.

2

Answers


  1. Create a tox.ini or .flake8 file in your project, and add your exceptions there. Flake8 should pick up on that.

    Login or Signup to reply.
  2. Use the flake8.severity setting contributed by the Flake8 extension. See https://flake8.pycqa.org/en/latest/user/configuration.html.

    Quoting from the docs, the default value is:

    {
      "convention": "Information",
      "error": "Error",
      "fatal": "Error",
      "refactor": "Hint",
      "warning": "Warning",
      "info": "Information"
    }
    

    The description in the docs is:

    Controls mapping of severity from flake8 to VS Code severity when displaying in the problems window. You can override specific flake8 error codes

    {
      "convention": "Information",
      "error": "Error",
      "fatal": "Error",
      "refactor": "Hint",
      "warning": "Warning",
      "W0611": "Error",
      "undefined-variable": "Warning"
    }
    

    Pay particular attention to the property W0611 in that example above. See also https://flake8.pycqa.org/en/latest/user/error-codes.html.

    Since Flake8 uses other plugins, you’ll need to refer to the readmes and docs of those plugins to find out what error codes they provide (I think Flake8 mostly just uses them without any sort of translation):

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search