Changed # pyright: basic file-level comment so it overrides "strict" settings specified in the config file or language server settings. This allows an individual file to be "downgraded" from strict to basic. This addresses https://github.com/microsoft/pyright/issues/4751.

This commit is contained in:
Eric Traut 2023-03-09 10:28:44 -07:00
parent 3f987e3137
commit 65ca325a14
2 changed files with 16 additions and 2 deletions

View File

@ -9,7 +9,7 @@ Strict type checking, where most supported type-checking switches generate error
# pyright: strict
```
Likewise, basic type checking can be enabled for a file.
Likewise, basic type checking can be enabled for a file. If you use `# pyright: basic`, the settings for the file use the default “basic” settings, not any override settings specified in the configuration file or language server settings. You can override the basic default settings within the file by specifying them individually (see below).
```python
# pyright: basic
@ -27,6 +27,7 @@ Diagnostic levels are also supported.
# pyright: reportPrivateUsage=warning, reportOptionalCall=error
```
### Line-level Diagnostic Suppression
PEP 484 defines a special comment `# type: ignore` that can be used at the end of a line to suppress all diagnostics emitted by a type checker on that line. Pyright supports this mechanism.

View File

@ -65,7 +65,7 @@ function _applyStrictRules(ruleSet: DiagnosticRuleSet) {
}
function _applyBasicRules(ruleSet: DiagnosticRuleSet) {
_overrideRules(ruleSet, getBasicDiagnosticRuleSet(), []);
_overwriteRules(ruleSet, getBasicDiagnosticRuleSet());
}
function _overrideRules(
@ -106,6 +106,19 @@ function _overrideRules(
}
}
function _overwriteRules(ruleSet: DiagnosticRuleSet, overrideRuleSet: DiagnosticRuleSet) {
const boolRuleNames = getBooleanDiagnosticRules();
const diagRuleNames = getDiagLevelDiagnosticRules();
for (const ruleName of boolRuleNames) {
(ruleSet as any)[ruleName] = (overrideRuleSet as any)[ruleName];
}
for (const ruleName of diagRuleNames) {
(ruleSet as any)[ruleName] = (overrideRuleSet as any)[ruleName];
}
}
function _parsePyrightComment(
commentValue: string,
commentRange: TextRange,