diff --git a/client/schemas/pyrightconfig.schema.json b/client/schemas/pyrightconfig.schema.json index 3b90b2010..cee61452f 100644 --- a/client/schemas/pyrightconfig.schema.json +++ b/client/schemas/pyrightconfig.schema.json @@ -222,6 +222,12 @@ "title": "Controls reporting input and return parameters whose types are unknown", "default": "none" }, + "reportUnknownLambdaType": { + "$id": "#/properties/reportUnknownLambdaType", + "$ref": "#/definitions/diagnostic", + "title": "Controls reporting input and return parameters for lambdas whose types are unknown", + "default": "none" + }, "reportUnknownVariableType": { "$id": "#/properties/reportUnknownVariableType", "$ref": "#/definitions/diagnostic", diff --git a/docs/configuration.md b/docs/configuration.md index 0fa82ce4c..ea8e2fc41 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -82,7 +82,9 @@ The following settings control pyright’s diagnostic output (warnings or errors **reportInvalidStringEscapeSequence** [boolean or string, optional]: Generate or suppress diagnostics for invalid escape sequences used within string literals. The Python specification indicates that such sequences will generate a syntax error in future versions. The default value for this setting is 'warning'. -**reportUnknownParameterType** [boolean or string, optional]: Generate or suppress diagnostics for input or return parameters that have an unknown type. The default value for this setting is 'none'. +**reportUnknownParameterType** [boolean or string, optional]: Generate or suppress diagnostics for input or return parameters for functions or methods that have an unknown type. The default value for this setting is 'none'. + +**reportUnknownLambdaType** [boolean or string, optional]: Generate or suppress diagnostics for input or return parameters for lambdas that have an unknown type. The default value for this setting is 'none'. **reportUnknownVariableType** [boolean or string, optional]: Generate or suppress diagnostics for variables that have an unknown type. The default value for this setting is 'none'. diff --git a/server/src/analyzer/typeAnalyzer.ts b/server/src/analyzer/typeAnalyzer.ts index c136d7124..a213cfbe9 100644 --- a/server/src/analyzer/typeAnalyzer.ts +++ b/server/src/analyzer/typeAnalyzer.ts @@ -590,13 +590,13 @@ export class TypeAnalyzer extends ParseTreeWalker { if (param.name) { const paramType = this._getTypeOfExpression(param.name); if (paramType.category === TypeCategory.Unknown) { - this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownParameterType, - DiagnosticRule.reportUnknownParameterType, + this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownLambdaType, + DiagnosticRule.reportUnknownLambdaType, `Type of '${ param.name.nameToken.value }' is unknown`, param.name); } else if (TypeUtils.containsUnknown(paramType)) { - this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownParameterType, - DiagnosticRule.reportUnknownParameterType, + this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownLambdaType, + DiagnosticRule.reportUnknownLambdaType, `Type of '${ param.name.nameToken.value }', ` + `'${ printType(paramType) }', is partially unknown`, param.name); @@ -606,12 +606,12 @@ export class TypeAnalyzer extends ParseTreeWalker { const returnType = this._getTypeOfExpression(node.expression); if (returnType.category === TypeCategory.Unknown) { - this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownParameterType, - DiagnosticRule.reportUnknownParameterType, + this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownLambdaType, + DiagnosticRule.reportUnknownLambdaType, `Type of lambda expression is unknown`, node.expression); } else if (TypeUtils.containsUnknown(returnType)) { - this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownParameterType, - DiagnosticRule.reportUnknownParameterType, + this._addDiagnostic(this._fileInfo.diagnosticSettings.reportUnknownLambdaType, + DiagnosticRule.reportUnknownLambdaType, `Type of lambda expression, '${ printType(returnType) }', is partially unknown`, node.expression); } diff --git a/server/src/common/configOptions.ts b/server/src/common/configOptions.ts index 7a84b90cb..2d6a3d937 100644 --- a/server/src/common/configOptions.ts +++ b/server/src/common/configOptions.ts @@ -123,9 +123,12 @@ export interface DiagnosticSettings { // Report usage of invalid escape sequences in string literals? reportInvalidStringEscapeSequence: DiagnosticLevel; - // Report usage of unknown input or return parameters? + // Report usage of unknown input or return parameters for functions? reportUnknownParameterType: DiagnosticLevel; + // Report usage of unknown input or return parameters for lambdas? + reportUnknownLambdaType: DiagnosticLevel; + // Report usage of unknown input or return parameters? reportUnknownVariableType: DiagnosticLevel; @@ -190,6 +193,7 @@ export function getDiagLevelSettings() { DiagnosticRule.reportIncompatibleMethodOverride, DiagnosticRule.reportInvalidStringEscapeSequence, DiagnosticRule.reportUnknownParameterType, + DiagnosticRule.reportUnknownLambdaType, DiagnosticRule.reportUnknownVariableType, DiagnosticRule.reportUnknownMemberType, DiagnosticRule.reportCallInDefaultInitializer, @@ -227,6 +231,7 @@ export function getStrictDiagnosticSettings(): DiagnosticSettings { reportIncompatibleMethodOverride: 'error', reportInvalidStringEscapeSequence: 'error', reportUnknownParameterType: 'error', + reportUnknownLambdaType: 'error', reportUnknownVariableType: 'error', reportUnknownMemberType: 'error', reportCallInDefaultInitializer: 'none', @@ -266,6 +271,7 @@ export function getDefaultDiagnosticSettings(): DiagnosticSettings { reportIncompatibleMethodOverride: 'none', reportInvalidStringEscapeSequence: 'warning', reportUnknownParameterType: 'none', + reportUnknownLambdaType: 'none', reportUnknownVariableType: 'none', reportUnknownMemberType: 'none', reportCallInDefaultInitializer: 'none', @@ -586,6 +592,11 @@ export class ConfigOptions { configObj.reportUnknownParameterType, DiagnosticRule.reportUnknownParameterType, defaultSettings.reportUnknownParameterType), + // Read the "reportUnknownLambdaType" entry. + reportUnknownLambdaType: this._convertDiagnosticLevel( + configObj.reportUnknownLambdaType, DiagnosticRule.reportUnknownLambdaType, + defaultSettings.reportUnknownLambdaType), + // Read the "reportUnknownVariableType" entry. reportUnknownVariableType: this._convertDiagnosticLevel( configObj.reportUnknownVariableType, DiagnosticRule.reportUnknownVariableType, diff --git a/server/src/common/diagnosticRules.ts b/server/src/common/diagnosticRules.ts index e15466112..cb17a3781 100644 --- a/server/src/common/diagnosticRules.ts +++ b/server/src/common/diagnosticRules.ts @@ -37,6 +37,7 @@ export const enum DiagnosticRule { reportIncompatibleMethodOverride = 'reportIncompatibleMethodOverride', reportInvalidStringEscapeSequence = 'reportInvalidStringEscapeSequence', reportUnknownParameterType = 'reportUnknownParameterType', + reportUnknownLambdaType = 'reportUnknownLambdaType', reportUnknownVariableType = 'reportUnknownVariableType', reportUnknownMemberType = 'reportUnknownMemberType', reportCallInDefaultInitializer = 'reportCallInDefaultInitializer',