Skip to content

Black formatter doesn't format anything with --diff argument #14148

Closed
@decastromonteiro

Description

@decastromonteiro

Environment data

  • VS Code version: 1.49.2
  • Extension version (available under the Extensions sidebar): v2020.9.111407
  • OS and version: Windows 10 - 10.0.18363
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: black version 20.8b1
  • Relevant/affected Python-related VS Code extensions and their versions: Python v2020.9.111407
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

When saving file, black formatter should format the file.

Sample file is:

a = {"1": 2, 
            "3": 3, 

"5": 4}

b = [
    1,
    2,
    3,
    4,
    5,
    6,
    7,8,9,10,10,101,10,101,0,131,
    2
]

Actual behaviour

On save, nothing changes on the file, the file remains unformatted.

Steps to reproduce:

  1. Select "black" as Python code formatter
  2. Copy the contents of the provided python code
  3. Save the file and see if anything happens

Logs

I see that vs code Python extensions uses the --diff key argument when using black. From black documentation it seems --diff doens't format the code, rather it only makes a diff.

--diff Don't write the files back, just output a diff for each file on stdout.

e:\VirtualEnviroments\Scripts\python.exe "c:/Users/Leonardo Monteiro/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet e:\thepacketwizards\web\blog\views\BlogCategory.py
cwd: e:\thepacketwizards
e:\VirtualEnviroments\Scripts\python.exe "c:/Users/Leonardo Monteiro/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" black --diff --quiet e:\thepacketwizards\web\blog\views\BlogCategory.py
cwd: e:\thepacketwizards
e:\VirtualEnviroments\Scripts\python.exe "c:/Users/Leonardo Monteiro/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s e:\thepacketwizards\web\blog\views\BlogCategory.py
cwd: e:\thepacketwizards
e:\VirtualEnviroments\Scripts\python.exe "c:/Users/Leonardo Monteiro/.vscode/extensions/ms-python.python-2020.9.111407/pythonFiles/pyvsc-run-isolated.py" flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s e:\thepacketwizards\web\blog\views\BlogCategory.py
cwd: e:\thepacketwizards
##########Linting Output - flake8##########

When running black without the diff argument, everything works as expected. Therefore I'm guessing this --diff argument should not be present when calling black.

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions