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.typeCheckingMode
off
off
: No type checking analysis is conducted; unresolved imports/variables diagnostics are producedbasic
: Non-type checking-related rules (all rules in off
) + basic type checking rulesstrict
: All type checking rules at the highest severity of error (includes all rules in off
and basic
categories)python.analysis.diagnosticMode
workspace
openFilesOnly
(default)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.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
Used to allow a user to override the severity levels for individual diagnostics should they desire.
Accepted severity values:
error
(red squiggle)warning
(yellow squiggle)information
(blue squiggle)none
(disables the rule)Available rule to use as keys can be found here
Example:
{
"python.analysis.diagnosticSeverityOverrides": {
"reportUnboundVariable": "information",
"reportImplicitStringConcatenation": "warning"
}
}
python.analysis.useLibraryCodeForTypes
true
(default)false
python.analysis.indexing
true
(default)false
python.analysis.userFileIndexingLimit
python.analysis.packageIndexDepths
Used to override how many levels under installed packages to index on a per package basis. By default, only top-level modules are indexed (depth = 1). To index submodules, increase depth by 1 for each level of submodule you want to index.
Accepted values:
{
"name": "package name (str)",
"depth": "depth to scan (int)",
"includeAllSymbols": "whether to include all symbols (bool)"
}
If include all symbols
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.
Example:
[
{ "name": "sklearn", "depth": 2, "includeAllSymbols": true },
{ "name": "matplotlib", "depth": 3, "includeAllSymbols": false }
]
python.analysis.autoImportCompletions
true
false
(default)python.analysis.importFormat
absolute
(default)relative
python.analysis.completeFunctionParens
true
false
(default)python.analysis.inlayHints.variableTypes
true
false
(default)python.analysis.inlayHints.functionReturnTypes
true
false
(default)python.analysis.inlayHints.callArgumentNames
off
(default)partial
all
python.analysis.inlayHints.pytestParameters
true
false
(default)@pytest.fixture()
def my_fixture() -> str:
return "foo"
def test_foo(my_fixture):...
@pytest.fixture()
def my_fixture() -> str:
return "foo"
def test_foo(my_fixture: str):...
python.analysis.fixAll
source.unusedImports
source.convertImportFormat
python.analysis.enablePytestSupport
true
(default)false
python.analysis.autoFormatStrings
{
in a string, automatically puts an f
on the front of the string.true
false
(default)python.analysis.autoIndent
true
(default)false
python.analysis.nodeExecutable
any executable path
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.