microsoft / microsoft/vscode-black-formatter
Saving changes to Python files with 'Format On Save' occasionally leads to duplicating the last few lines or symbols (using Black Formatter)
- Dominant language
- Python
- Stars
- 196
- Forks
- 49
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 7
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version:
```
Version: 1.107.1
Commit: 994fd12f8d3a5aa16f17d42c041e5809167e845a
Date: 2025-12-17T14:15:14.850Z
Electron: 39.2.3
ElectronBuildId: 12895514
Chromium: 142.0.7444.175
Node.js: 22.21.1
V8: 14.2.231.21-electron.0
OS: Linux x64 6.8.0-90-generic
```
- OS Version: Ubuntu 22.04
Example. The last two lines on the screenshot were duplicated twice over multiple Save+Format on save executions:
Steps to Reproduce:
1. Create a Python file with some code
2. Save with format-on-save (e.g., Black) multiple times (might require some violation of the PEP8 style to take effect)
3. Observe new statements (valid or invalid) appear at the end of the file
The issue has been there for a few months.
Contributor guide
Research direction
Start by reproducing this with a Python file in VS Code 1.107.1, Black, and format-on-save, saving repeatedly after introducing a formatting change. Trace the format-on-save flow and compare the document contents across saves; done means repeated saves no longer append or duplicate trailing lines or symbols.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, vscode
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100