Added config switch for reportUnknownLambdaType.

This commit is contained in:
Eric Traut 2019-10-04 23:39:04 -07:00
parent bc6dd0265a
commit 41058eb22b
5 changed files with 30 additions and 10 deletions

View File

@ -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",

View File

@ -82,7 +82,9 @@ The following settings control pyrights 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'.

View File

@ -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);
}

View File

@ -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,

View File

@ -37,6 +37,7 @@ export const enum DiagnosticRule {
reportIncompatibleMethodOverride = 'reportIncompatibleMethodOverride',
reportInvalidStringEscapeSequence = 'reportInvalidStringEscapeSequence',
reportUnknownParameterType = 'reportUnknownParameterType',
reportUnknownLambdaType = 'reportUnknownLambdaType',
reportUnknownVariableType = 'reportUnknownVariableType',
reportUnknownMemberType = 'reportUnknownMemberType',
reportCallInDefaultInitializer = 'reportCallInDefaultInitializer',