Documentation and issues for Pylance
This repository is for providing feedback and documentation on the Pylance language server extension in Visual Studio Code. You can use the repository to report issues or submit feature requests. The Pylance codebase is not open-source but you can contribute to Pyright to make improvements to the core typing engine that powers the Pylance experience.
Pylance is the default language support for Python in Visual Studio Code and is shipped as part of that extension as an optional dependency.
Note: If you’ve previously set a language server and want to try Pylance, make sure you’ve set "python.languageServer": "Default" or "Pylance"
in your settings.json file using the text editor, or using the Settings Editor UI.
Pylance provides some awesome features for Python 3, including:
See the changelog for the latest release.
Pylance provides users with the ability to customize their Python language support via a host of settings which can either be placed in the settings.json
file in your workspace, or edited through the Settings Editor UI.
python.analysis.languageServerMode
Offers predefined configurations to help users optimize Pylance’s performance based on their development needs. It controls how many IntelliSense features Pylance provides, allowing you to choose between full language service functionality or a lightweight experience optimized for performance.
Default value: default
Available values:
light
default
(default)full
Description:
default
: Provides a balanced experience with many useful features enabled by default. It ensures that the language server delivers sufficient functionality for most users without overloading the system. Advanced features can be enabled as needed, allowing for further customization at the cost of performance.light
: Designed for users seeking a lightweight, memory-efficient setup. This mode disables various features to make Pylance function more like a streamlined text editor. Ideal for those who do not require the full breadth of IntelliSense capabilities and prefer Pylance to be as resource-friendly as possible.full
: Designed for users seeking the most extensive feature set. This mode enables most of Pylance’s features, offering the richest IntelliSense experience. Ideal for those who want access to the full range of available functionality.Individual settings can be configured to override the defaults set by languageServerMode
.
Default settings based on mode are:
Mode | light | default | full |
---|---|---|---|
python.analysis.exclude | [“**”] | [] | [] |
python.analysis.useLibraryCodeForTypes | false | true | true |
python.analysis.enablePytestSupport | false | true | true |
python.analysis.indexing | false | true | true |
python.analysis.autoImportCompletions | false | false | true |
python.analysis.showOnlyDirectDependenciesInAutoImport | false | false | true |
python.analysis.packageIndexDepths | See | settings | below |
python.analysis.regenerateStdLibIndices | false | false | true |
python.analysis.userFileIndexingLimit | 2000 | 2000 | -1 |
python.analysis.includeAliasesFromUserFiles | false | false | true |
python.analysis.functionReturnTypes | false | false | true |
python.analysis.pytestParameters | false | false | true |
python.analysis.supportRestructuredText | false | false | true |
python.analysis.supportDocstringTemplate | false | false | true |
python.analysis.typeCheckingMode
off
.
Note that the value of this setting can be overridden by having a pyrightconfig.json or a pyproject.toml. For more information see this link.
off
: No type checking analysis is conducted; unresolved imports/variables diagnostics are producedbasic
: All off
rules + basic type checking rulesstandard
: All off
rules + basic type checking rules + standard type checking rulesstrict
: All off
rules + all type checking rules.python.analysis.typeCheckingMode
to off
can improve performance by disabling type checking analysis, which can be resource-intensive, especially in large codebases.python.analysis.diagnosticMode
workspace
openFilesOnly
(default)python.analysis.diagnosticMode
to openFilesOnly
limits analysis to open files, improving performance by reducing the amount of code Pylance needs to process in large workspaces.python.analysis.include
**
(a directory or multiple levels of directories), *
(a sequence of zero or more characters), or ?
(a single character).python.analysis.exclude
**
(a directory or multiple levels of directories), *
(a sequence of zero or more characters), or ?
(a single character). If no exclude paths are specified, Pylance automatically excludes the following: **/node_modules
, **/__pycache__
, .git
and any virtual environment directories.["**"]
in light
mode)python.analysis.exclude
to ["**"]
will exclude all files except those currently open, minimizing resource consumption.python.analysis.ignore
**
(a directory or multiple levels of directories), *
(a sequence of zero or more characters), or ?
(a single character).python.analysis.stubPath
./typings
python.analysis.autoSearchPaths
src
).true
(default)false
python.analysis.extraPaths
python.autoComplete.extraPaths
setting.python.analysis.diagnosticSeverityOverrides
error
(red squiggle)warning
(yellow squiggle)information
(blue squiggle)none
(disables the rule){
"python.analysis.diagnosticSeverityOverrides": {
"reportUnboundVariable": "information",
"reportImplicitStringConcatenation": "warning"
}
}
python.analysis.typeEvaluation
{
"python.analysis.typeEvaluation.enableReachabilityAnalysis": true,
"python.analysis.typeEvaluation.strictDictionaryInference": false
}
python.analysis.disableTaggedHints
true
false
(default)python.analysis.useLibraryCodeForTypes
true
(or false
in light
mode)true
(default)false
python.analysis.useLibraryCodeForTypes
to false
can improve performance by preventing Pylance from parsing the source code of third-party libraries when type stubs are unavailable, thereby reducing resource usage.true
(or false
in light
mode)true
(default)false
python.analysis.indexing
to false
can improve performance by reducing resource consumption, especially in large projects, at the cost of making features like auto-imports and workspace symbol search find fewer symbols.python.analysis.userFileIndexingLimit
full
mode)python.analysis.packageIndexDepths
[
{ "name": "sklearn", "depth": 2 },
{ "name": "matplotlib", "depth": 2 },
{ "name": "scipy", "depth": 2 },
{ "name": "django", "depth": 2 },
{ "name": "flask", "depth": 2 },
{ "name": "fastapi", "depth": 2 }
]
or in full
mode[
{ "name": "", "depth": 4, "includeAllSymbols": true }
]
{
"name": "package name (str)",
"depth": "depth to scan (int)",
"includeAllSymbols": "whether to include all symbols (bool)"
}
If includeAllSymbols
is set to false
, only symbols in each package’s __all__
are included. When it’s set to true
, Pylance will index every module/top level symbol declarations in the file.[
{ "name": "sklearn", "depth": 2, "includeAllSymbols": true },
{ "name": "matplotlib", "depth": 3, "includeAllSymbols": false }
]
python.analysis.regenerateStdLibIndices
stdlib.json
indices for all Python versions, generate unique indices tailored to each workspace’s specific Python version and platform. This regeneration process will affect performance, unlike using the prebuilt stdlib indices.false
(or true
in full
mode)true
false
(default)python.analysis.includeAliasFromUserFiles
add import
and auto import
.false
(or true
in full
mode)true
false
(default)python.analysis.autoImportCompletions
false
(or true
in full
mode)true
false
(default)python.analysis.autoImportCompletions
can impact performance by increasing the number of completion items and resource usage. Disabling it can improve performance by reducing the computational overhead during code completion.python.analysis.showOnlyDirectDependenciesInAutoImport
requirements.txt
or pyproject.toml
in auto import
suggestions, if they exist. This only affects auto import
for completions. The add import
code action will continue to show all possible imports.false
(or true
in full
mode)true
false
(default)python.analysis.importFormat
absolute
(default)relative
python.analysis.completeFunctionParens
true
false
(default)python.analysis.completeFunctionParens
can slightly improve performance by reducing the overhead during code completion, though the impact is minimal.python.analysis.inlayHints.variableTypes
true
false
(default)python.analysis.inlayHints.variableTypes
to false
can improve performance by reducing the processing required to generate these hints, which can be beneficial in large codebases.python.analysis.inlayHints.functionReturnTypes
false
(or true
in full
mode)true
false
(default)python.analysis.inlayHints.callArgumentNames
off
(default)partial
all
python.analysis.inlayHints.callArgumentNames
to off
can improve performance by reducing the processing needed to display argument names during function calls.python.analysis.inlayHints.pytestParameters
false
(or true
in full
mode)true
false
(default)def test_foo(my_fixture):
assert(my_fixture)
becomesdef test_foo(my_fixture: str):
assert(my_fixture)
python.analysis.fixAll
fixall
.source.unusedImports
source.convertImportFormat
python.analysis.enablePytestSupport
true
(or false
in light
mode)true
(default)false
python.analysis.enablePytestSupport
to false
can improve performance by reducing the overhead associated with providing IntelliSense features for pytest fixtures.python.analysis.autoFormatStrings
{
in a string, automatically puts an f
on the front of the string.true
false
(default)python.analysis.autoFormatStrings
can slightly improve performance by reducing the processing required during string formatting, though the impact is minimal.python.analysis.nodeExecutable
any executable path
python.analysis.autoIndent
true
(default)false
python.analysis.supportRestructuredText
false
(or true
in full
mode)true
false
(default)python.analysis.supportRestructuredText
to false
can improve performance by reducing the overhead of parsing complex docstrings.python.analysis.aiCodeActions
true
false
(default)implementAbstractClasses
.{
"python.analysis.aiCodeActions": {
"implementAbstractClasses": true
}
}
python.analysis.supportDocstringTemplate
false
(or true
in full
mode)true
false
(default)def foo(arg):
"""
|<Trigger completions here
"""
python.analysis.displayEnglishDiagnostics
true
false
(default)Visual Studio Code uses TextMate grammars as the main tokenization engine. TextMate grammars work on a single file as input and break it up based on lexical rules expressed in regular expressions.
Semantic tokenization allows language servers to provide additional token information based on the language server’s knowledge on how to resolve symbols in the context of a project. Themes can opt-in to use semantic tokens to improve and refine the syntax highlighting from grammars. The editor applies the highlighting from semantic tokens on top of the highlighting from grammars.
Here’s an example of what semantic highlighting can add:
Without semantic highlighting:
With semantic highlighting:
Semantic colors can be customized in settings.json by associating the Pylance semantic token types and modifiers with the desired colors.
Semantic token types
Semantic token modifiers
The scope inspector tool allows you to explore what semantic tokens are present in a source file and what theme rules they match to.
Example of customizing semantic colors in settings.json:
{
"editor.semanticTokenColorCustomizations": {
"[One Dark Pro]": {
// Apply to this theme only
"enabled": true,
"rules": {
"magicFunction:python": "#ee0000",
"function.declaration:python": "#990000",
"*.decorator:python": "#0000dd",
"*.typeHint:python": "#5500aa",
"*.typeHintComment:python": "#aaaaaa"
}
}
}
}
source.unusedImports
source.convertImportFormat
python.analysis.importFormat
.source.fixall.pylance
python.analysis.fixall
settingKnown issues are documented in TROUBLESHOOTING.
Pylance leverages Microsoft’s open-source static type checking tool, Pyright, to provide performant language support for Python.
Code contributions are welcomed via the Pyright repo.
Pylance ships with a collection of type stubs for popular modules to provide fast and accurate auto-completions and type checking. Our type stubs are sourced from typeshed and our work-in-progress stub repository, microsoft/python-type-stubs. Type stubs in microsoft/python-type-stubs will be contributed back to typeshed or added inline to source packages once they are of high enough quality.
For information on getting started, refer to the CONTRIBUTING instructions.
See LICENSE for more information.