question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting with black doesn't update the file in-place

See original GitHub issue

Environment data

  • VS Code version: 1.56.2
  • Extension version (available under the Extensions sidebar): v2021.5.842923320
  • OS and version: Arch Linux 5.12.5
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.8, using pyenv
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pyenv. I think it’s virtualenv under the hood?
  • Value of the python.languageServer setting: Pylance

Expected behaviour

When formatting a python file with black, from the palette, right clicking, or format-on-save, the file should be updated with the changes.

Actual behaviour

The black process can be seen running, but the file does not get updated.

Steps to reproduce:

  1. Write a python file with a '' wrapped string (black should convert this to "")
  2. set up black as formatter
  3. format the file

Logs

> ~/.pyenv/versions/shiphero-shipping/bin/python ~/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/workspace/shiphero/Shiphero-API/shipping/shipping/application/quoting.py.43d88024a1c151b0045448c575b5425b.tmp
cwd: ~/workspace/shiphero/Shiphero-API
> ~/.pyenv/versions/shiphero-shipping/bin/python ~/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/pyvsc-run-isolated.py black --diff --quiet ~/workspace/shiphero/Shiphero-API/shipping/shipping/application/quoting.py.43d88024a1c151b0045448c575b5425b.tmp
cwd: ~/workspace/shiphero/Shiphero-API

Formatting with black failed.
Error: Invalid patch string: --- /home/lacrymology/workspace/shiphero/Shiphero-API/shipping/shipping/application/quoting.py.43d88024a1c151b0045448c575b5425b.tmp	2021-05-28 17:46:43.167718 +0000

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
Lacrymologycommented, Jun 18, 2021

@karrtikr issue was that someone added the color = true option to the project’s pyproject.toml file, so the diff contained color markers and it didn’t apply. Sorry

0reactions
karrtikrcommented, Jun 18, 2021

@Lacrymology Glad you were able to diagnose that🎉

@CalebEverett Your issue seems different, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The basics - Black 22.12.0 documentation
You can run Black as a package if running it as a script doesn't work: ... By default Black reformats the files given...
Read more >
How to Auto-Format Your Python Code with Black
black --check . : This will check which python file(s) can be formatted in the current folder (but doesn't actually modify the python...
Read more >
Formatter black is not working on my VSCode...but why?
Just run from the command line if you need to format a lot of files at once. First, check if you have this...
Read more >
black · PyPI
Black is a PEP 8 compliant opinionated formatter. Black reformats entire files in place. Style configuration options are deliberately limited and rarely added....
Read more >
Stylising your Python code: An introduction to linting and ...
Black reformats entire files in place, applying its own PEP8-compliant coding style which is detailed here. Examples. Formatting a Python script.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found