mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed issue with chained config files related to typeCheckingMode.
This commit is contained in:
parent
421dabee57
commit
1466ccb653
@ -591,7 +591,11 @@ export class AnalyzerService {
|
||||
}
|
||||
}
|
||||
|
||||
const configOptions = new ConfigOptions(projectRoot, this._typeCheckingMode);
|
||||
const configOptions = new ConfigOptions(projectRoot);
|
||||
configOptions.initializeTypeCheckingMode(
|
||||
this._typeCheckingMode,
|
||||
commandLineOptions.diagnosticSeverityOverrides
|
||||
);
|
||||
const defaultExcludes = ['**/node_modules', '**/__pycache__', '**/.*'];
|
||||
|
||||
if (commandLineOptions.pythonPath) {
|
||||
@ -657,6 +661,8 @@ export class AnalyzerService {
|
||||
|
||||
configOptions.disableTaggedHints = !!commandLineOptions.disableTaggedHints;
|
||||
|
||||
configOptions.initializeTypeCheckingMode(commandLineOptions.typeCheckingMode ?? 'standard');
|
||||
|
||||
const configs = this._getExtendedConfigurations(configFilePath ?? pyprojectFilePath);
|
||||
|
||||
if (configs) {
|
||||
@ -664,7 +670,6 @@ export class AnalyzerService {
|
||||
configOptions.initializeFromJson(
|
||||
config.configFileJsonObj,
|
||||
config.configFileDirUri,
|
||||
this._typeCheckingMode,
|
||||
this.serviceProvider,
|
||||
host,
|
||||
commandLineOptions
|
||||
|
@ -987,9 +987,6 @@ export class ConfigOptions {
|
||||
// Minimum threshold for type eval logging
|
||||
typeEvaluationTimeThreshold = 50;
|
||||
|
||||
// Current type checking mode.
|
||||
typeCheckingMode?: string;
|
||||
|
||||
// Was this config initialized from JSON (pyrightconfig/pyproject)?
|
||||
initializedFromJson = false;
|
||||
|
||||
@ -1047,10 +1044,9 @@ export class ConfigOptions {
|
||||
// Controls how hover and completion function signatures are displayed.
|
||||
functionSignatureDisplay: SignatureDisplayType;
|
||||
|
||||
constructor(projectRoot: Uri, typeCheckingMode?: string) {
|
||||
constructor(projectRoot: Uri) {
|
||||
this.projectRoot = projectRoot;
|
||||
this.typeCheckingMode = typeCheckingMode;
|
||||
this.diagnosticRuleSet = ConfigOptions.getDiagnosticRuleSet(typeCheckingMode);
|
||||
this.diagnosticRuleSet = ConfigOptions.getDiagnosticRuleSet();
|
||||
this.functionSignatureDisplay = SignatureDisplayType.formatted;
|
||||
}
|
||||
|
||||
@ -1101,11 +1097,21 @@ export class ConfigOptions {
|
||||
return [this.getDefaultExecEnvironment()];
|
||||
}
|
||||
|
||||
initializeTypeCheckingMode(
|
||||
typeCheckingMode: string | undefined,
|
||||
severityOverrides?: DiagnosticSeverityOverridesMap
|
||||
) {
|
||||
this.diagnosticRuleSet = ConfigOptions.getDiagnosticRuleSet(typeCheckingMode);
|
||||
|
||||
if (severityOverrides) {
|
||||
this.applyDiagnosticOverrides(severityOverrides);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the structure from a JSON object.
|
||||
initializeFromJson(
|
||||
configObj: any,
|
||||
configDirUri: Uri,
|
||||
typeCheckingMode: string | undefined,
|
||||
serviceProvider: ServiceProvider,
|
||||
host: Host,
|
||||
commandLineOptions?: CommandLineOptions
|
||||
@ -1190,7 +1196,6 @@ export class ConfigOptions {
|
||||
}
|
||||
|
||||
// If there is a "typeCheckingMode", it can override the provided setting.
|
||||
let configTypeCheckingMode: string | undefined = this.typeCheckingMode;
|
||||
if (configObj.typeCheckingMode !== undefined) {
|
||||
if (
|
||||
configObj.typeCheckingMode === 'off' ||
|
||||
@ -1198,7 +1203,7 @@ export class ConfigOptions {
|
||||
configObj.typeCheckingMode === 'standard' ||
|
||||
configObj.typeCheckingMode === 'strict'
|
||||
) {
|
||||
configTypeCheckingMode = configObj.typeCheckingMode;
|
||||
this.diagnosticRuleSet = { ...ConfigOptions.getDiagnosticRuleSet(configObj.typeCheckingMode) };
|
||||
} else {
|
||||
console.error(`Config "typeCheckingMode" entry must contain "off", "basic", "standard", or "strict".`);
|
||||
}
|
||||
@ -1212,15 +1217,6 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
this.typeCheckingMode = configTypeCheckingMode || typeCheckingMode;
|
||||
const defaultSettings = ConfigOptions.getDiagnosticRuleSet(this.typeCheckingMode);
|
||||
|
||||
// Start with the default values for all rules in the rule set.
|
||||
this.diagnosticRuleSet = { ...defaultSettings };
|
||||
|
||||
// Apply host-provided overrides.
|
||||
this.applyDiagnosticOverrides(commandLineOptions?.diagnosticSeverityOverrides);
|
||||
|
||||
// Apply overrides from the config file for the boolean rules.
|
||||
getBooleanDiagnosticRules(/* includeNonOverridable */ true).forEach((ruleName) => {
|
||||
(this.diagnosticRuleSet as any)[ruleName] = this._convertBoolean(
|
||||
|
@ -216,7 +216,7 @@ test('PythonPlatform', () => {
|
||||
const nullConsole = new NullConsole();
|
||||
|
||||
const sp = createServiceProvider(fs, nullConsole);
|
||||
configOptions.initializeFromJson(json, cwd, undefined, sp, new NoAccessHost());
|
||||
configOptions.initializeFromJson(json, cwd, sp, new NoAccessHost());
|
||||
|
||||
const env = configOptions.executionEnvironments[0];
|
||||
assert.strictEqual(env.pythonPlatform, 'platform');
|
||||
@ -343,7 +343,7 @@ test('verify config fileSpecs after cloning', () => {
|
||||
const rootUri = Uri.file(process.cwd(), fs);
|
||||
const config = new ConfigOptions(rootUri);
|
||||
const sp = createServiceProvider(fs, new NullConsole());
|
||||
config.initializeFromJson(configFile, rootUri, undefined, sp, new TestAccessHost());
|
||||
config.initializeFromJson(configFile, rootUri, sp, new TestAccessHost());
|
||||
const cloned = deserialize(serialize(config));
|
||||
|
||||
assert.deepEqual(config.ignore, cloned.ignore);
|
||||
@ -385,5 +385,5 @@ test('Extended config files', () => {
|
||||
assert.deepStrictEqual(fileNames, ['sample.pyi', 'test.py']);
|
||||
|
||||
const configOptions = service.test_getConfigOptions(commandLineOptions);
|
||||
assert.equal(configOptions.typeCheckingMode, 'strict');
|
||||
assert.equal(configOptions.diagnosticRuleSet.strictListInference, true);
|
||||
});
|
||||
|
@ -180,10 +180,10 @@ export class TestState {
|
||||
const configOptions = this._convertGlobalOptionsToConfigOptions(vfsInfo.projectRoot, mountPaths);
|
||||
|
||||
if (this.rawConfigJson) {
|
||||
configOptions.initializeTypeCheckingMode('standard');
|
||||
configOptions.initializeFromJson(
|
||||
this.rawConfigJson,
|
||||
Uri.file(projectRoot, this.serviceProvider),
|
||||
'standard',
|
||||
this.serviceProvider,
|
||||
testAccessHost
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user