VSCode Pylance Extension Usage and Setup Instructions

Beatme CodeBY-NC-ND
37:30 read·4877 words· published

VSCode Pylance Extension

The Pylance extension in VSCode provides powerful support for Python language development, such as smart hints, completions, diagnostics and analysis of code. In general, this extension will be installed with VSCode’s Python extension and will be the Python language server recognized by the Python extension.

When will the VSCode Pylance extension be activated?

If the Pylance extension is not disabled, it will be activated when VSCode opens any code file that is parsed into the Python language (e.g., the common py file) or when VSCode detects the presence of the file pyrightconfig.json in the root directory of the workspace during startup.

The VSCode Pylance extension only diagnoses Python code files in text format

The Pylance extension only diagnoses problems with Python code files in text format; Pylance does not or cannot diagnose problems with compiled bytecode files, Python files in other binary formats, and files in compressed files in zip format.

The VSCode Pylance extension only analyzes Python code files in text format

If the Python module used in the code does not have a corresponding type stub file, then the Pylance extension will attempt to analyze the corresponding text format code file (including the code file presents in the zip compressed file) of the module for smart hints and completions of the code in VSCode, but for compiled bytecode files, Python files in other binary formats, Pylance will not or cannot analyze them.

The concepts of analysis and diagnosis may create some confusion, and we need to think of diagnosis as part of analysis, which may or may not take place in the process of analysis.

What is a Python type stub file?

Python type stub files, which have the extension pyi, can contain Python code just like py code files, except that type stub files generally keep only the key code related to the definition, and use for the rest of the file (e.g., the body code of a function or a method), in order to minimize the size of the file.

Python type stub files can be used by the Pylance extension for code smart hints, completions, diagnostics, etc., usually for installed Python third-party packages or modules. If the Python module to be analyzed has a corresponding pyi type stub file, then the module’s corresponding py file or any other form of file will be ignored. The directory structure of the directory holding Python type stub files should be consistent with the directory structure of the directory in the Python Module Search Path where the module or package is imported.

Configure VSCode

For information on how to specify the default Python language server, you can check the section Install the VSCode Pylance Extension.

Set up VSCode Pylance Extension

Like most VSCode extensions, Pylance provides developers with settings that allow you to tweak and change some of the functionality implemented by the Pylance extension by editing the setting.json file in the .vscode folder of your workspace or by editing the related items in VSCode’s Settings Panel.

Set up Python Type Checking Feature of the VSCode Pylance Extension

The setting item python.analysis.typeCheckingMode of the Pylance extension can be used to set Pylance’s Python type checking mode. Different type checking modes correspond to different Python type checking rulesets, and are categorized into the following modes, from loose to strict.

off mode

The off mode is the default value for the python.analysis.typeCheckingMode setting item, which means that Python code is not type-checked, and is only diagnosed for invalid syntax, undefined content (variables, functions, etc.), and imports that are unresolved (e.g., imports of inaccessible Python modules or packages, or imports of non-existent content).

basic mode

The basic mode contains all the rules in the off mode, as well as basic Python type checking rules, such as that unknown class attributes should not be accessed, and that methods or functions should be called with all the necessary parameters.

standard mode

The standard mode contains all the rules in the off mode, as well as the basic and standard Python type checking rules, and is therefore stricter than the basic mode.

strict mode

The strict mode is the strictest type checking mode, and contains all the rules in the off mode, as well as all the Python type checking rules, e.g., reporting variables or parameters whose types cannot be derived.

settings.json
{
	// The strictest mode strict
	"python.analysis.typeCheckingMode": "strict",
}

The Pylance extension's type checking does not prevent VSCode from running Python code

While Pylance extension’s type checking feature can detect various problems in your code and display them in VSCode’s Problems Panel, Pylance does not prevent Python code from running or debugging.

How do I customize the severity level of Python type checking rules?

Each Python type checking rule has its own severity level, and VSCode and Pylance can perform different actions based on these severity levels. The Pylance extension’s setting item, python.analysis.diagnosticSeverityOverrides, is an object (default is {}) containing a series of attributes that can be used to customize the severity level of a Python type checking rule, where the name of the attribute is the name of the type checking rule and the value of the attribute is one of the following, error (red wavy line, equivalent to the boolean value true), warning (yellow wavy line), information (blue wavy line), none (disable rule, equivalent to boolean value false).

Detailed information on all the rules for Python type checking can be found at GitHub.

pyright/docs/configuration.md at main · microsoft/pyright

settings.json
{
	// Customize the severity level of Python type checking rules
	"python.analysis.diagnosticSeverityOverrides": {
		// Imports that cannot be resolved
		"reportMissingImports": "warning"
	},
}

Set Python Files to be Diagnosed by the VSCode Pylance Extension

The Pylance extension’s setting item python.analysis.diagnosticMode can be used to set the scope in which Pylance will diagnose Python code files, and the problems obtained from diagnosis will be displayed in VSCode’s Problems Panel, and the valid values for this setting item are the following two.

openFilesOnly mode

The openFilesOnly mode is the default value for the python.analysis.diagnosticMode setting item, which indicates that Pylance only diagnoses Python code files that have been opened in VSCode.

workspace mode

The workspace mode means that Pylance will diagnose all Python code files in the VSCode workspace, as well as Python code files opened by VSCode.

settings.json
{
	// Diagnose all and opened Python code files in the workspace
	"python.analysis.diagnosticMode": "workspace",
}

All Python code files in the VSCode workspace will only be diagnosed after the Pylance extension is activated

It should be noted that setting python.analysis.diagnosticMode to workspace mode does not change the way the Pylance extension is activated, and you may need to proactively open a py file to initiate the task of diagnosing all Python code files.

How do I set files that need to be diagnosed by the VSCode Pylance extension?

The Pylance extension’s setting item python.analysis.include (its default value is []) is an array containing path information, and when the setting item python.analysis.diagnosticMode is workspace, only Python code files whose beginning of the path matches any item in the array will be diagnosed by Pylance (of course, files opened directly by VSCode will also be diagnosed), which means that if python.analysis.include gives the path to a folder, then Python code files in that folder and all its subfolders will be diagnosed by Pylance.

If python.analysis.include does not give any path, such as the default value [], then Pylance will diagnose Python code files in the root directory of the VSCode workspace and all its subdirectories.

The python.analysis.include setting item of the Pylance extension can include relative or absolute paths

If you use a relative path in the Pylance setting item python.analysis.include, the relative path will be calculated from the root directory of VSCode’s workspace, e.g., src\ and .\src\ (Windows) both indicate the src folder in the workspace. In addition to relative paths, it is possible to use absolute paths in python.analysis.include, whether or not they are included in VSCode’s current workspace, and yes, Pylance can diagnose Python code files outside the workspace.

The python.analysis.include setting item of the Pylance extension can contain path wildcards

The python.analysis.include setting item of Pylance can contain a number of path wildcard characters, for example, ? denotes a single character in a file or folder name, * denotes zero or more characters in a file or folder name, and ** denotes any path combining zero or more folders.

The following setting item, python.analysis.include, contains a set of paths in Windows.

settings.json
{
	// The path information of the files to be diagnosed
	"python.analysis.include": [
		// Three-character folders beginning with s and c
		"s?c\\",
		// First-level subfolders of the src folder
		"src\\*\\",
		// Files or folders in the src folder or any of its subfolders that end with s.py
		"src\\**\\*s.py"
	],
}

How do I set files that need to be excluded from diagnostics by the VSCode Pylance extension?

The Pylance extension’s setting item python.analysis.exclude (its default value is []) is an array containing path information, and when the setting item python.analysis.diagnosticMode has the value workspace, a Python code file whose beginning of the path matches any item in the array will not be diagnosed by Pylance (excluding files opened directly by VSCode), even if it matches the path information in the python.analysis.include setting item.

If python.analysis.exclude does not give any paths, e.g., the default value [], then Pylance will exclude all Python code files in all folders (which can also be files) named node_modules, __pycache__ or .git in the VSCode workspace.

The python.analysis.exclude setting item can use relative paths, absolute paths, and path wildcards, similar to python.analysis.include.

Python code files excluded by the python.analysis.exclude setting item may still be diagnosed by Pylance

If a Python code file is excluded by the python.analysis.exclude setting item, it may still be diagnosed by Pylance when the file is opened in VSCode, or when it is imported or referenced by other Python code files that can be diagnosed. It should be noted that the exact implementation of this feature will depend on the circumstances of each case.

The following setting item, python.analysis.exclude, contains a path in Windows.

settings.json
{
	// Path information for files that do not require diagnostics
	"python.analysis.exclude": [
		// A file or folder ending with test.py in the src folder or any subfolder
		"src\\**\\*test.py"
	],
}

Set Python Files that Ignore Diagnostic Results from the VSCode Pylance Extension

The Pylance extension’s setting item python.analysis.ignore (its default value is []) is an array containing path information, so that if the beginning of the path of a particular Python code file matches one of the items in this array, then Pylance’s diagnostic results (including errors and warnings) about the file will be ignored (not displayed).

Similar to the python.analysis.include setting item, python.analysis.ignore can also use relative paths, absolute paths, and path wildcards.

The following setting item, python.analysis.ignore, contains a path in Windows.

settings.json
{
	// Path information for files that ignore diagnostic results
	"python.analysis.ignore": [
		// The first-level subfolders of the src folder whose name contains test
		"src\\*test*\\"
	],
}

Set the Python Type Stub File Directory for the VSCode Pylance Extension

The python.analysis.stubPath setting item of the Pylance extension can be used to specify the directory where the Python type stub files are located, similar to python.analysis.include, where you can take a relative or absolute path. The default value of python.analysis.stubPath is typings, which is the typings folder in the root directory of the VSCode workspace.

Problems with VSCode Pylance extension using Python type stub files

Since the Pylance extension itself manages type stub files in addition to the type stub file directory specified by the python.analysis.stubPath setting item, some strange phenomena may occur. For example, when writing code in VSCode to import a Python module and use its functions or variables, Pylance provides smart hints and completions, but executing the Python code shows that the module was not found ModuleNotFoundError. The reason for this may be that Pylance is using the corresponding type stub file for the Python module, the code file for the module itself does not exist, or the Python Module Search Path is set incorrectly, preventing the module from being located. In this case, of course, Pylance will tell you that the module cannot be imported from the source.

settings.json
{
	// Specify the type stub file directory as the my_typings folder in the workspace
	"python.analysis.stubPath": "my_typings",
}

The setting item python.analysis.useLibraryCodeForTypes of the Pylance extension is a boolean value that can be used to specify whether or not to analyze the Python code file corresponding to a Python module that needs to be analyzed when the module doesn’t have a corresponding type stub file; the default value is true, which analyzes the corresponding code file.

The VSCode Pylance extension will analyze Python packages that have a py.typed file

If a regular Python package (non-namespace package) does not have a type stub file, but its corresponding folder contains the file py.typed, then the Pylance extension will analyze that Python package, as well as all of the package’s regular subpackages (non-namespace packages) and submodules, even if python.analysis. useLibraryCodeForTypes is set to false.

settings.json
{
	// This will not analyze the module's corresponding code file when the type stub file does not exist
	"python.analysis.useLibraryCodeForTypes": false,
}

Set Extra Python Module Paths for the VSCode Pylance Extension

The Pylance extension’s setting item python.analysis.extraPaths (its default value is []) is an array containing information about extra module paths, and Pylance attempts to find and analyze the code files corresponding to Python modules in these paths when they are imported. It should be noted that extra module paths do not affect Python’s own Module Search Path.

In terms of paths, python.analysis.extraPaths is similar to the python.analysis.include setting item in that you can use relative paths, absolute paths, and path wildcards. Paths in python.analysis.extraPaths need to point to a folder or a zip compressed file, pointing to anything else may not work.

Problems with VSCode Pylance extension using extra Python module paths

Similar to the use of Python type stub files, the use of the Pylance extension with extra Python module paths can cause code that has no problem after diagnosis to indicate that the module was not found ModuleNotFoundError at runtime, one of the reasons for this is that the Python Module Search Path is not able to locate the modules in the extra module paths.

When you encounter this, you can either adjust the Python Module Search Path to include the directory pointed to by the extra module path, or modify the statement that imports the module.

settings.json
{
	// Extra Python module paths
	"python.analysis.extraPaths": [
		// Search for modules in extra.zip in the root directory of the workspace
		"extra.zip"
	],
}

The Pylance extension’s setting item python.analysis.autoSearchPaths is a boolean value that can be used to specify whether to enable automatic Python Module Search Paths or not; by setting python.analysis.autoSearchPaths to true (the default value), Pylance can try to find and analyze the code files corresponding to Python modules from some predefined paths (e.g., the src folder in the root directory of the VSCode workspace) when they are imported.

In terms of effect, the automatic Module Search Paths are similar to the extra module paths, except that the paths in python.analysis.autoSearchPaths are preset, while the paths in python.analysis.extraPaths are specified by the developer. The automatic Module Search Paths also do not affect Python’s own Module Search Path, and may indicate that the module was not found ModuleNotFoundError at runtime.

settings.json
{
	// Disable the automatic Python Module Search Paths
	"python.analysis.autoSearchPaths": false,
}

Set up Python Indexing Feature of the VSCode Pylance Extension

The Pylance extension’s setting item, python.analysis.indexing, can be used to control whether or not user files (Python code files in the VSCode workspace, whose corresponding modules should have valid fully qualified names), Python third-party packages or modules are indexed (the default is true, indexed). Effective indexing is a prerequisite for Pylance to automatically import modules, add import statements, and so on.

Which Python third-party packages or modules are indexed by the VSCode Pylance extension?

In addition to modules located directly in the Python third-party package directories, all namespace packages in the third-party package directories, and all subpackages and submodules in namespace packages, the Pylance extension can index any third-party package or module, although the ability to do so will of course be affected by other setting items.

settings.json
{
	// Disable Python indexing
	"python.analysis.indexing": false,
}

The Pylance extension’s setting item python.analysis.packageIndexDepths is an array containing indexing schemes, and different Python packages can have different indexing schemes. By default, Pylance indexes only Python packages located directly in third-party package directories (excluding modules, and subpackages or submodules within packages).

If you want to index subpackages or submodules of a Python package, you need to set the depth setting item of the corresponding scheme to 2 (the default is 1), and the name setting to the name of the Python package, and if you want to index subpackages or submodules of a subpackage, you need to set the depth setting item to 3, and so on. If you want to index all attributes of a Python package or module, you need to set the includeAllSymbols setting item of the corresponding scheme to true, in some cases includeAllSymbols doesn’t work and Pylance will index all attributes.

The Pylance extension’s setting item python.analysis.persistAllIndices is a boolean (the default is true, save) that can be used to set whether or not to save the compiled indexes for Python’s third-party packages and modules as json index files in the .cache subfolder of the dist folder of the Pylance extension installation directory for next use. If python.analysis.persistAllIndices is set to false, the json index files will not be used, even if they already exist.

The setting item python.analysis.userFileIndexingLimit of the Pylance extension can be used to set the maximum number of user files for indexing, which defaults to 2000, and if it is set to -1, it means that there is no limit to the number of user files that can participate in indexing. Setting it to -1 is not recommended due to the fact that indexing can involve a large number of operations in a short period of time.

VSCode Pylance extension's json index files for Python packages and modules may not be updated

The json index file stored by the Pylance extension may not be updated, either by modifying a setting item or by editing code in Python packages and modules, unless the contents of the index have increased or there is a reason why it must be updated.

You can run the command pylance.indexing.clearPersistedIndices from the VSCode Command Palette to clear all json index files, or try to find and delete the json index files corresponding to Python packages to re-index them.

The VSCode Pylance extension always indexes Python code files that have been opened

Python code files opened directly by VSCode (the module corresponding to the file should have a valid fully qualified name) will be indexed, regardless of the values of the setting items python.analysis.indexing and python.analysis.userFileIndexingLimit.

settings.json
{
	// This will not index Python code files in the workspace, unless they are opened
	"python.analysis.userFileIndexingLimit": 0,
	// Indexing scheme for the third-party package named just_test
	"python.analysis.packageIndexDepths": [
		{ "name": "just_test", "depth": 3, "includeAllSymbols": true }
	],
}

Set up Code Completion Feature of the VSCode Pylance Extension

The Pylance extension’s setting item, python.analysis.autoImportCompletions, can be used to set whether or not to enable Python import statement completion (the default is false, which does not do import statement completion), which automatically writes import or from…import to import Python modules when you use the module’s attributes and have not imported the module. If python.analysis.indexing is set to false, then Pylance’s import statement completion is only available for Python code files that have been opened in VSCode (the module corresponding to the file should have a valid fully qualified name).

The Pylance extension’s setting item, python.analysis.importFormat, can be used to set the format of Python’s import statement completion, and its valid values include the following two.

absolute format

The absolute format is the default value for the python.analysis.importFormat setting item, which indicates that the Python import statement is to be completed with a fully qualified name.

relative format

The relative format indicates that the Python import statement should be completed with relative names wherever possible, or fully qualified names if this is not possible.

The Pylance extension’s setting item, python.analysis.completeFunctionParens, can be used to set whether to enable Python function or method parenthesis completion, which automatically writes parentheses () after a function or method is selected to be called; the default is false, which does not perform function or method parenthesis completion.

The Pylance extension’s setting item, python.analysis.autoFormatStrings, can be used to set whether or not to complement Python strings with the prefix f when you write { in the string (note that this feature fails to have the desired effect in some cases). The default value of python.analysis.autoFormatStrings is false, which does not do prefix f completion.

settings.json
{
	// Enable completion of import statements
	"python.analysis.autoImportCompletions": true,
	// Completion of import statements uses relative names
	"python.analysis.importFormat": "relative",
	// Enable parenthesis completion for functions or methods
	"python.analysis.completeFunctionParens": true,
	// Enable f prefix completion of strings (may have no effect)
	"python.analysis.autoFormatStrings": true,
}

Set up Code Inlay Hint Feature of the VSCode Pylance Extension

The Pylance extension’s setting item, python.analysis.inlayHints.variableTypes, can be used to set whether or not to enable the inlay hint feature for variable types (the default is false, which doesn’t enable it), which embeds a description of a variable’s type when you don’t specify the variable’s type using : and the variable type needs a clear description. For example, a=[1,2] will have the description embedded, b=1 or c=set() will not.

The Pylance extension’s setting item, python.analysis.inlayHints.functionReturnTypes, can be used to set whether or not to enable the inlay hint feature for function or method return values (the default is false, which doesn’t enable it), which embeds a description of the type of the function or method return value when you do not use -> to specify the type of the function or method return value.

The Pylance extension’s setting item, python.analysis.inlayHints.callArgumentNames, can be used to set whether to enable the inlay hint feature for parameter names, which attempts to embed parameter names for arguments when the name of that argument is not specified, to help the developers understand the meaning of the argument efficiently. Valid values for the python.analysis.inlayHints.callArgumentNames setting item include the following.

off

off is the default value of the python.analysis.inlayHints.callArgumentNames setting item, which indicates that the inlay hint feature for parameter names are disabled.

partial

partial indicates that if a argument is both a positional and named parameter, an attempt is made to embed the parameter name for it.

all

all indicates an attempt to embed parameter names for all arguments.

The Pylance extension’s setting item, python.analysis.inlayHints.pytestParameters, can be used to set whether or not to enable the inlay hint feature for the parameter types of a pytest function or method (the default is false, which does not enable it), which attempts to embed a description of the parameter type when Python’s pytest package is able to infer the type of a parameter and the parameter does not use : to specify the type. Note that use of the python.analysis.inlayHints.pytestParameters setting item assumes that the pytest package is available and that the python.analysis.enablePytestSupport setting item has a value of true.

The setting item python.analysis.enablePytestSupport for the Pylance extension is a boolean that can be used to set whether or not to enable support for the pytest package, which defaults to true, enable.

Functions

For a detailed look at Python functions, parameters, and return values, you can check out the article Introduction to Python Functions, Parameters, Return Values; Define and Call Python Functions.

settings.json
{
	// Enable inlay hints for variable types
	"python.analysis.inlayHints.variableTypes": true,
	// Enable inlay hints for return value types
	"python.analysis.inlayHints.functionReturnTypes": true,
	// Enable inlay hints for all parameter names
	"python.analysis.inlayHints.callArgumentNames": "all",
	// Enable inlay hints for the parameter types of pytest functions or methods
	"python.analysis.inlayHints.pytestParameters": true,
	// Disable support for pytest, which will invalidate the pytestParameters setting item
	"python.analysis.enablePytestSupport": false,
}

Set up Code Navigation Feature of the VSCode Pylance Extension

The Pylance extension’s setting item, python.analysis.gotoDefinitionInStringLiteral, can be used to set whether or not to enable module navigation feature for Python strings (the default is true, which enables it), which provides navigation for literals that are considered to be modules in Python strings. For example, for sys in "sys is here", you can use the context menu or shortcut key for sys to jump to the code file or type stub file associated with the module sys.

settings.json
{
	// Disable module navigation for strings
	"python.analysis.gotoDefinitionInStringLiteral": false,
}

Set up Logging Feature of the VSCode Pylance Extension

The python.analysis.logLevel setting item of the Pylance extension, which can be used to set what Pylance outputs as a log, has the following valid values.

Error level

The Error level indicates that only errors are output to the log.

Warning level

The Warning level indicates that errors and warnings are output to the log.

Information level

The Information level is the default value for the setting item python.analysis.logLevel, which indicates that errors, warnings, and information are output to the log.

Trace level

The Trace level indicates that errors, warnings, information and traces are output as logs.

What are the logs of the VSCode Pylance extension?

As the name suggests, Pylance logs are output by the extension Pylance as it runs, and these can be viewed in the Python Language Server item of VSCode Output Panel.

settings.json
{
	// Set Pylance to report errors only
	"python.analysis.logLevel": "Error",
}

Set the Behavior of the VSCode Pylance Extension in the FixAll Command

The Pylance extension’s setting item python.analysis.fixAll is an array of strings (its default value is []), and each item in the array corresponds to a behavior that determines how the Pylance extension behaves when the Fix All command is executed; the following are valid values for the python.analysis.fixAll array.

source.unusedImports behavior

The source.unusedImports behavior removes some import statements from Python code files that have been opened in VSCode because they import modules that are not being used.

source.convertImportFormat behavior

The source.convertImportFormat behavior will convert import statements in Python code files that have been opened in VSCode based on the setting item python.analysis.importFormat.

What is the Fix All command of VSCode?

The Fix All command is used to try to fix all code problems and can be executed by typing Fix All in VSCode’s Command Palette.

settings.json
{
	// Set the behavior when running the Fix All command
	"python.analysis.fixAll": [
		"source.unusedImports",
		"source.convertImportFormat"
	],
}

Set the Path to the Node.js Executable Running the VSCode Pylance Extension

The setting item python.analysis.nodeExecutable (which defaults to an empty string) of the Pylance extension is used to indicate an external Node.js executable that Pylance will run through this external Node.js. In general, Pylance uses VSCode’s own Node.js, and its memory is limited by VSCode, so if you want more memory space, then setting the python.analysis.nodeExecutable setting item is possible.

The value of the python.analysis.nodeExecutable setting item is not limited to the path of the Node.js executable, it can also be an alias pointing to Node.js, but in any case you should make sure that the value is able to start Node.js correctly on the command line.

The use of the Pylance extension's python.analysis.nodeExecutable setting item in VSCode workspace settings is not supported

The python.analysis.nodeExecutable setting item of the Pylance extension is not supported in the VSCode workspace settings, i.e. the settings.json file in the .vscode folder. Setting the python.analysis.nodeExecutable setting item needs to be done in VSCode user settings or remote settings.

settings.json
{
	// External Node.js (not available in VSCode workspace settings)
	"python.analysis.nodeExecutable": "node",
}

Customize Python Syntax Highlighting Styles for the VSCode Pylance Extension

The editor.semanticTokenColorCustomizations setting item allows you to customize the Python syntax highlighting styles of the Pylance extension for a particular theme or for all themes of VSCode, mainly with respect to colors, of course. The following are the specific semantic token types and semantic token modifiers supported by the Pylance extension that can be used to customize Python syntax highlighting styles. In practice, the names of items should be suffixed with :python to restrict them to only work in the Python language, and all items should be placed in the rules setting.

Semantic token types include, but are not limited to, class, enum, parameter, variable, property, enumMember, function, member, module, intrinsic, magicFunction. selfParameter, clsParameter. Semantic token modifiers include, but are not limited to, declaration, readonly, static, abstract, async, typeHint, typeHintComment, decorator, builtin.

How can I view the semantic token type and semantic token modifiers that Python code belongs to in VSCode?

If you don’t know the semantic token type and semantic token modifiers of a Python code element, you can start the Scope Inspector by typing the command Developer: Inspect Editor Tokens and Scopes in the VSCode Command Palette, and clicking on the code element that you want to see, and the panel will show you the semantic token type, the semantic token modifiers, and other relevant information.

settings.json
{
	// Customize Python syntax highlighting for all themes
	"editor.semanticTokenColorCustomizations": {
		"rules": {
			// Specify the color of the class
			"class:python": "#da9797",
			// Specify the color of declarations, e.g., class and function definitions
			"*.declaration:python": "#82cb7a"
		}
	}
}

Source Code

settings.json·codebeatme/python·GitHub