Format on Save (Black) stopped working with latest update
- VS Code Version: Version: 1.98.0 (Universal)
- OS Version: MacOS Sequoia 15.3.1
After installing the latest update, I noticed that neither my linter (flake8) nor my formatter (black) worked within VS code (meanwhile the command line functionality was fine, so this is an issue with VS code, not my global installations). I found this related issue https://github.com/microsoft/vscode/issues/108447 and I found a partial solution: my default formatter had been set to Null after the update, and once I corrected this, python black works again within VS code. However, it appears my linter still does not work, and in that issue I could not find any guidance for what should be modified to restore the settings of my linter.
I was mistaken when I said the linter does not work. At least, after shutting down and restarting the editor, the flake8 linter seems to work fine in the sense that code errors are highlighted as expected.
The problem just seems to be with format on save with black. I have checked that Editor: Format on Save is checked, and that Format on Save Mode is set to file. And if I format with black from the command line, it works fine. Maybe there is just some other simple setting that got changed with the update that I need to change back, but I haven't been able to find it.
afaik nothing has changed in this area, I also use format-on-save dialy (tho for TypeScript). Please double check your config and the extension
Well I resolved at least one other issue that happened after the update: I had previously checked the box for "remove trailing whitespace, but this was unchecked after updating. I have now rechecked that box. I'm not sure what other settings were changed by the update.
I am accustomed to using format-on-save daily and so I would very much like to restore this behavior, but I still have not figured out what is broken about my settings/config. I have tried uninstalling and reinstalling the following extensions: black formatter, flake8, python, and pylance. I guess I could try deleting vs code and installing from scratch.
Curiously, aspects of format-on-save work. For example, isort works just fine when I format-on-save. But most other things do not work. @jrieken since you tagged this issue with info-needed, could you let me know what would be the most helpful information to help me get to the bottom of this issue?
Which Python are you using? I just found this via google trying to diagnose the same issue, turns out I had 3.12.5 installed which is not supported by black since 24.10.0.
24.10.0 Highlights Black will issue an error when used with Python 3.12.5, due to an upstream memory safety issue in Python 3.12.5 that can cause Black's AST safety checks to fail. Please use Python 3.12.6 or Python 3.12.4 instead. (#4447) Black no longer supports running with Python 3.8 (#4452)
The new black extension shipped 25.1.0. It didn't work for me with Python 3.12.5, works with 3.12.9.
Perhaps you have a different problem but I thought I'd chime in with a possible solution. Also, if you access the command palette you can search for "show logs" and see what black formatter extension spits out.
@matkozak - many thanks for chiming in! Yes, I do indeed have python 3.12.5 installed in the virtual environment where I am running black in vs code. I will try upgrading the env to 3.12.9.
@matkozak thanks again for taking the time to post this solution - I confirm that switching to python 3.12.9 solves the issue. Thanks also to @jrieken for putting time into this. Much appreciated!
So, I think this issue can be closed. However, I would be happy to change the title of this issue to make it more discoverable, so if anyone has thoughts on this let me know.
I confirm that switching to python 3.12.9 solves the issue.
Moving to @rebornix to follow up on this
This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.
Happy Coding!
This broke a working format on save with Python 3.9 yet the same settings work with Python 3.11
eback (most recent call last): File "c:\Users\$$$$\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_server.py", line 531, in _run_tool_on_document result = utils.run_module( File "c:\Users\$$$$\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_utils.py", line 171, in run_module return _run_module(module, argv, use_stdin, source) File "c:\Users\$$$$\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_utils.py", line 156, in _run_module runpy.run_module(module, run_name="__main__") File "c:\Program Files\Python\Python39\lib\runpy.py", line 202, in run_module mod_name, mod_spec, code = _get_module_details(mod_name) File "c:\Program Files\Python\Python39\lib\runpy.py", line 144, in _get_module_details return _get_module_details(pkg_main_name, error) File "c:\Program Files\Python\Python39\lib\runpy.py", line 107, in _get_module_details __import__(pkg_name) File "c:...