Added support for "reportUntypedNamedTuple" switch.

This commit is contained in:
Eric Traut 2019-05-01 18:43:45 -07:00
parent 718d00fa92
commit 76697a8252
4 changed files with 19 additions and 0 deletions

View File

@ -139,6 +139,12 @@
"title": "Controls reporting of a base class of an unknown type, which obscures most type checking for the class",
"default": "none"
},
"reportUntypedNamedTuple": {
"$id": "#/properties/reportUntypedNamedTuple",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of a named tuple definition that does not contain type information",
"default": "none"
},
"reportPrivateUsage": {
"$id": "#/properties/reportPrivateUsage",
"$ref": "#/definitions/diagnostic",

View File

@ -54,6 +54,8 @@ The following settings control pyright's diagnostic output (warnings or errors).
**reportUntypedBaseClass** [boolean or string, optional]: Generate or suppress diagnostics for base classes whose type cannot be determined statically. These obscure the class type, defeating many type analysis features. The default value for this setting is 'none'.
**reportUntypedNamedTuple** [boolean or string, optional]: Generate or suppress diagnostics when “namedtuple” is used rather than “NamedTuple”. The former contains no type information, whereas the latter does. The default value for this setting is 'none'.
**reportPrivateUsage** [boolean or string, optional]: Generate or suppress diagnostics for uses of private variables or functions outside of the class or module that declares them. Private variables and functions, by convention, are named starting with a single underscoe (“_”) character. The default value for this setting is 'none'.
**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'.

View File

@ -1155,6 +1155,10 @@ export class ExpressionEvaluator {
// The stdlib collections/__init__.pyi stub file defines namedtuple
// as a function rather than a class, so we need to check for it here.
if (callType.getBuiltInName() === 'namedtuple') {
this._addDiagnostic(
this._fileInfo.configOptions.reportUntypedNamedTuple,
`'namedtuple' provides no types for tuple entries. Use 'NamedTuple' instead.`,
errorNode);
type = this._createNamedTupleType(errorNode, argList, false, cachedCallType);
} else {
type = this._validateCallArguments(errorNode, argList, callType, new TypeVarMap());

View File

@ -118,6 +118,9 @@ export class ConfigOptions {
// Report untyped base class that obscure the class type?
reportUntypedBaseClass: DiagnosticLevel = 'none';
// Report use of untyped namedtuple factory method?
reportUntypedNamedTuple: DiagnosticLevel = 'none';
// Report usage of private variables and functions outside of
// the owning class or module?
reportPrivateUsage: DiagnosticLevel = 'none';
@ -286,6 +289,10 @@ export class ConfigOptions {
this.reportUntypedBaseClass = this._convertDiagnosticLevel(
configObj.reportUntypedBaseClass, 'reportUntypedBaseClass', 'none');
// Read the "reportUntypedNamedTuple" entry.
this.reportUntypedNamedTuple = this._convertDiagnosticLevel(
configObj.reportUntypedNamedTuple, 'reportUntypedNamedTuple', 'none');
// Read the "reportPrivateUsage" entry.
this.reportPrivateUsage = this._convertDiagnosticLevel(
configObj.reportPrivateUsage, 'reportPrivateUsage', 'none');