Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python AutoPep8 formatting not working with max line length parameter

I noticed one strange thing that autopep8 autoformatting in VSCode doesn't work when we set

    "python.formatting.autopep8Args": [
        "--line-length 119"
    ],

But if this setting is in a default mode that is line length 79 then it works well. Is there some issue with autopep8 to work only with line length 79 not more than that, or I am making any mistake in VSCode. Major feature that I need is when my python program line goes too long it should be able to break it in multiple lines. I don't want to go ahead with 79 characters' approach. My preferred approach is 119 characters. Currently, I have to indent big lines manually. Is there any other format apart from pep8 which supports 119 characters and indent lines with characters more than 119 characters automatically.

I am attaching my settings.json file data

{
    "window.zoomLevel": 1,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.fontSize": 16,
    "python.formatting.provider": "autopep8",
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "python.autoComplete.addBrackets": true,
    "python.formatting.autopep8Args": [
        "--line-length 119"
    ],
    // "python.linting.flake8Args": [
    //     "--max-line-length=120"
    // ],
    "files.autoSaveDelay": 10000,
    "editor.defaultFormatter": "ms-python.python",
    "files.autoSave": "afterDelay",
    "files.trimTrailingWhitespace": true,
    "files.trimFinalNewlines": true,
    "editor.quickSuggestions": true,
    "editor.codeActionsOnSave": null,
}
like image 451
Mohit Kumar Avatar asked Aug 08 '20 10:08

Mohit Kumar


2 Answers

experimental worked for me

"python.formatting.autopep8Args": ["--max-line-length", "120", "--experimental"]

check out this link for proper format specifier settings

like image 187
senti143 Avatar answered Sep 29 '22 05:09

senti143


This should work -

"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
    "--max-line-length",
    "120",
    "--experimental"
]
like image 32
PD Wanjari Avatar answered Sep 29 '22 06:09

PD Wanjari