-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Environment data
- VS Code version: 1.47.3
- Extension version (available under the Extensions sidebar): 2020.7.96456
- OS and version: MacOS
- Python version (& distribution if applicable, e.g. Anaconda): 3.8
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
- Relevant/affected Python packages and their versions: black==19.10b0
- Value of the
python.languageServersetting: Pylance
Expected behaviour
When 'editor.formatOnSave' is set to true and 'python.formatting.provider' is set to 'black', saving a ".pyi" stub file should auto-format in the same way as a ".py" file.
Actual behaviour
After modifying a ".pyi" file and saving, extra lines are emitted between each method/function, and an extra line is added at the end of the file. Saving the file a second time reformats again and removes the extra lines between method/functions but leaves the extra line at the end of the file. When submitting this type stub file to typeshed, it fails CI because black indicates that there is an extra line at the end of the file.
If I invoke black directly from the terminal tab on the file, it correctly auto-formats the first time — i.e. it doesn't add any extra lines.
This screen shot shows what happens when "format on save" is enabled (after the first save).

This screen shot shows what happens after the second save. Note that there is an extra line left at the bottom.

This screen shot shows what happens when I manually call black directly from the terminal.

Steps to reproduce:
Create or open a type stub file (ending in ".pyi") that contains a class with multiple methods.
Configure your editor for "format on save" with black as the formatter.
Save the file once. Save it a second time.