Pylance is a fast, feature-rich language support extension for Python in Visual Studio Code, powered by the Pyright static type checker. It provides type checking, completions, navigation, refactorings, and code actions that help keep Python codebases consistent.
One of those code actions is Pylance Fix All. The python.analysis.fixAll setting controls which Pylance fixes are included when you run that action.
python.analysis.fixAll is an array of fix commands. When Pylance runs its Fix All code action, it applies only the commands listed in this setting.
The default value is an empty array:
"python.analysis.fixAll": []That means source.fixAll.pylance does not apply any changes until you explicitly opt in to one or more fix commands.
python.analysis.fixAll currently supports these values:
source.unusedImports- Remove unused imports.
source.convertImportFormat- Convert import format according to the
python.analysis.importFormatsetting.
- Convert import format according to the
source.convertImportStar- Convert wildcard imports such as
from module import *into explicit imports.
- Convert wildcard imports such as
source.addTypeAnnotation- Add type annotations to variables and functions when Pylance can infer them.
You can configure python.analysis.fixAll in your workspace or user settings.json.
"python.analysis.fixAll": [
"source.unusedImports"
]"python.analysis.fixAll": [
"source.unusedImports",
"source.convertImportFormat",
"source.convertImportStar",
"source.addTypeAnnotation"
]Use a smaller list if you want a more conservative Fix All workflow.
After you configure python.analysis.fixAll, you can use VS Code's Fix All workflow for the current file.
Pylance uses the configured list when VS Code runs Fix All or requests fix-all source actions. In practice, that means the Pylance fixes you opted into are the ones available through the source.fixAll.pylance code action.
For example, if you configure:
"python.analysis.fixAll": [
"source.unusedImports",
"source.convertImportStar"
]then Pylance Fix All applies only those two fixes.
You can also run Pylance Fix All automatically through VS Code's save actions.
Add source.fixAll.pylance to editor.codeActionsOnSave in your settings.json:
{
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll.pylance": "explicit"
}
}
}This tells VS Code to run the Pylance fix-all source action on save for Python files, using whatever commands you configured in python.analysis.fixAll.
For example:
{
"python.analysis.fixAll": ["source.unusedImports", "source.convertImportFormat"],
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll.pylance": "explicit"
}
}
}With that configuration, saving a Python file runs Pylance Fix All and applies only unused-import removal and import-format conversion.
python.analysis.importFormat- Used by
source.convertImportFormatto decide whether imports should be written in absolute or relative form.
- Used by
If python.analysis.fixAll is left at its default empty array, source.fixAll.pylance has no configured fixes to apply.
No. It controls the fixes applied by Pylance's source.fixAll.pylance code action.
Yes. Add only the commands you want to the array. For example, if you want Fix All to remove unused imports but nothing else, configure only source.unusedImports.
For more information on Pylance settings and customization, refer to the Pylance Settings and Customization documentation.