Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/configuration/config-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,21 @@ The following settings allow more fine grained control over the **typeCheckingMo


## Execution Environment Options
Pyright allows multiple execution environments to be defined for different portions of your source tree. For example, a subtree may be designed to run with different import search paths or a different version of the python interpreter than the rest of the source base.
Pyright allows multiple "execution environments" to be defined for different portions of your source tree. For example, a subtree may be designed to run with different import search paths or a different version of the python interpreter than the rest of the source base.

The following settings can be specified for each execution environment. Each source file within a project is associated with at most one execution environment -- the first one whose root directory contains that file.

- **root** [string, required]: Root path for the code that will execute within this execution environment.

- **extraPaths** [array of strings, optional]: Additional search paths (in addition to the root path) that will be used when searching for modules imported by files within this execution environment. If specified, this overrides the default extraPaths setting when resolving imports for files within this execution environment. Note that each file’s execution environment mapping is independent, so if file A is in one execution environment and imports a second file B within a second execution environment, any imports from B will use the extraPaths in the second execution environment.
- **typeCheckingMode** [string, optional]: Specifies the type checking mode to use for this execution environment. This overrides the global `typeCheckingMode` setting. Valid values are the same as the global setting: `"off"`, `"basic"`, `"standard"`, `"strict"`, `"recommended"`, or `"all"`. If not specified, the global `typeCheckingMode` is used. This provides a cleaner alternative to specifying individual diagnostic rule overrides when you want to apply a different strictness level to specific folders.

- **extraPaths** [array of strings, optional]: Additional search paths (in addition to the root path) that will be used when searching for modules imported by files within this execution environment. If specified, this overrides the default extraPaths setting when resolving imports for files within this execution environment. Note that each file's execution environment mapping is independent, so if file A is in one execution environment and imports a second file B within a second execution environment, any imports from B will use the extraPaths in the second execution environment.

- **pythonVersion** [string, optional]: The version of Python used for this execution environment. If not specified, the global `pythonVersion` setting is used instead.

- **pythonPlatform** [string, optional]: Specifies the target platform that will be used for this execution environment. If not specified, the global `pythonPlatform` setting is used instead.

In addition, any of the [type check diagnostics settings](config-files.md#type-check-diagnostics-settings) listed above can be specified. These settings act as overrides for the files in this execution environment.
In addition, any of the [type check diagnostics settings](config-files.md#type-check-diagnostics-settings) listed above can be specified. These settings act as overrides for the files in this execution environment. Individual diagnostic rule overrides take precedence over the `typeCheckingMode` setting.

## Sample Config File
The following is an example of a pyright config file:
Expand Down Expand Up @@ -364,20 +366,22 @@ The following is an example of a pyright config file:
"root": "src/web",
"pythonVersion": "3.5",
"pythonPlatform": "Windows",
"typeCheckingMode": "basic",
"extraPaths": [
"src/service_libs"
],
"reportMissingImports": "warning"
]
},
{
"root": "src/sdk",
"pythonVersion": "3.0",
"typeCheckingMode": "strict",
"extraPaths": [
"src/backend"
]
},
{
"root": "src/tests",
"typeCheckingMode": "standard",
"reportPrivateUsage": false,
"extraPaths": [
"src/tests/e2e",
Expand Down Expand Up @@ -411,9 +415,9 @@ pythonVersion = "3.6"
pythonPlatform = "Linux"

executionEnvironments = [
{ root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ], reportMissingImports = "warning" },
{ root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] },
{ root = "src/tests", reportPrivateUsage = false, extraPaths = ["src/tests/e2e", "src/sdk" ]},
{ root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", typeCheckingMode = "basic", extraPaths = [ "src/service_libs" ] },
{ root = "src/sdk", pythonVersion = "3.0", typeCheckingMode = "strict", extraPaths = [ "src/backend" ] },
{ root = "src/tests", typeCheckingMode = "standard", reportPrivateUsage = false, extraPaths = ["src/tests/e2e", "src/sdk" ]},
{ root = "src" }
]
```
Expand Down
26 changes: 25 additions & 1 deletion packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2030,10 +2030,34 @@ export class ConfigOptions {
configExtraPaths: Uri[]
): ExecutionEnvironment | undefined {
try {
// If typeCheckingMode is specified for this execution environment,
// use it to generate the base diagnostic rule set. Otherwise, use
// the config-level diagnostic rule set.
let baseDiagnosticRuleSet = configDiagnosticRuleSet;
if (envObj.typeCheckingMode !== undefined) {
if (typeof envObj.typeCheckingMode === 'string') {
if ((allTypeCheckingModes as readonly string[]).includes(envObj.typeCheckingMode)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cast we have to do here is annoying. since this was copied from initializeTypeCheckingModeFromString maybe we can extract some of this logic into a helper function

Copy link
Owner

@DetachHead DetachHead Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the ai write this? it looks like it's duplicated even more now. is it trying to replace the initializeTypeCheckingModeFromString and initializeTypeCheckingMode functions with this new getDiagnosticRuleSetFromString function? if so, how come it's only called in one spot but the existing usages of those functions are still there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed

baseDiagnosticRuleSet = this.constructor.getDiagnosticRuleSet(
envObj.typeCheckingMode as TypeCheckingMode
);
} else {
console.error(
`Config executionEnvironments index ${index}: invalid "typeCheckingMode" value: "${
envObj.typeCheckingMode
}". Expected: ${userFacingOptionsList(allTypeCheckingModes)}`
);
}
} else {
console.error(
`Config executionEnvironments index ${index}: typeCheckingMode must be a string.`
);
}
}

const newExecEnv = new ExecutionEnvironment(
this._getEnvironmentName(),
configDirUri,
configDiagnosticRuleSet,
baseDiagnosticRuleSet,
configPythonVersion,
configPythonPlatform,
configExtraPaths
Expand Down
Loading
Loading