The 'Black' formatter - Python

14.9k views Asked by At

I just started using the 'Black' formatter module with Visual Studio Code. Everything was going well till I just noticed that it uses double quotes over single quotes which I already was using in my code... And it overrode that...

So, is there an Black argument that I could add to Visual Studio Code which solves this problem?

4

There are 4 answers

0
FlipperPA On BEST ANSWER

You can use the --skip-string-normalization option at the command line, or in your Visual Studio Code options.

See The Black code style, Strings.

For example:

{
    ...
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--skip-string-normalization",
        "--line-length",
        "100"
    ]
    ...
}
0
Shub On

Go to settings, search for black and add argument -S.

0
Al Mahdi On

--skip-string-normalization or -S for short

{
    ...

    "python.formatting.blackArgs": [
        "-S"
    ],
    ...
}
3
OM26R On

I don't know how it works for you all of that:

 {
    ...
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--skip-string-normalization"
    ]
    ...
}

or

{
    ...

    "python.formatting.blackArgs": [
        "-S"
    ],
    ...
}

I've tried everything and THE ONLY works for me is:

"black-formatter.args": ["-S"]

And VSCode for some reason installed via pip install -U black , don't know it is crucial or not.