I want so format my python code
in vscode
for function|class definitions, with a formatter obeying these 2 criteria for splitting into new line:
- the line has exceeded 40 characters
- the line has exceeded 3 args in a line
criteria 1 illustration
if the line is longer it should split so:
def longerFunctionName(arg1, arg2, arg3, arg4, arg5): #// assume character length limit is 30
would be
def longerFunctionName(arg1,
arg2, arg3, arg4,
arg5):
criteria 2 illustration
so if a line in a definitions has 4 args, after the 3rd one should be splitted like
def func(arg1, arg2, arg3, arg4):
should be
def func(arg1, arg2, arg3,
arg4):
tries
in settings.json
I have tried:
"[python]": {
"python.formatting.autopep8Args": [
"--max-line-length=40",
"--indent-size=4",
"--indent-after-paren=1",
"--aggressive",
"--max-args=3"
]
}
or
"[python]": {
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["-l", "40"],
"editor.formatOnType": true,
}
which don't work as I want;
- with 79 char limit changes
def skmfdskmkfn_kfdks_kfmdckdsmk(dfkekrm=["df", "dfdnfkmem"], dfkekrm2=["df", "dfdnfkmem"], dfkekrm3=["df", "dfdnfkmem"],):
dfkekrm3
to
def skmfdskmkfn_kfdks_kfmdckdsmk(
dfkekrm=["df", "dfdnfkmem"],
dfkekrm2=["df", "dfdnfkmem"],
dfkekrm3=["df", "dfdnfkmem"],
):
dfkekrm3
note it could have kept some args in one line till 80 character. like
def skmfdskmkfn_kfdks_kfmdckdsmk(dfkekrm=["df", "dfdnfkmem"],
dfkekrm2=["df", "dfdnfkmem"], dfkekrm3=["df", "dfdnfkmem"],):
dfkekrm3
- even don't work in case of more than 3 args
def longerFunctionName(arg1, arg2, arg3, arg4, arg5):
arg1
note keeps the following unchanged but it was supposed to split after 3 args