I'm using VSCode and have configured black and flake8 for dev container. My settings.json
looks like this:
{
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.mypyEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length",
"88",
"--ignore=E203,W503,W504"
],
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.formatting.blackArgs": [
"--line-length",
"88",
"--experimental-string-processing"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"autoDocstring.docstringFormat": "google"
}
Since black's default maximum line length is 88, I've explicitly set the flake8
and black
configuration to 88 to avoid conflicts. However, when I have a single string exceeding 89 characters, flake8
warns with an E501 error ("line too long"), but black
doesn't automatically format it. Even if I manually fix the error reported by flake8
to bring it below 88 characters, running "format document" with black
reverts the string to its original length.
Here's an example:
from modeling.estimation.performance_analysis.monte_carlo.least_squares.error_grids import BaseGrid
I encountered an E501 error from flake8
and fixed it manually:
from modeling.estimation.performance_analysis.monte_carlo.least_squares.error_grids import ( \
BaseGrid,
)
However, upon running "format document" with black
, the string reverts to the original length:
from modeling.estimation.performance_analysis.monte_carlo.least_squares.error_grids import BaseGrid
In a previously posted question, there was a suggestion to use # fmt: off/on
as a workaround.
Is there a way to enable the line length limits of both black
and flake8
as intended without using # fmt: off/on
?