@zzzen/pyright-internal 1.2.0-dev.20230917 → 1.2.0-dev.20230924
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +60 -3
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +1 -1
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructors.js +6 -0
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/decorators.js +2 -2
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +3 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +7 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +1 -0
- package/dist/analyzer/sourceMapper.js +9 -4
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +63 -17
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +4 -3
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typedDicts.js +20 -16
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -0
- package/dist/analyzer/types.js +8 -2
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +1 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/common/pathUtils.js +1 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +2 -2
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -1
- package/dist/common/serviceProvider.js +6 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +4 -1
- package/dist/languageService/autoImporter.js +12 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/localization/package.nls.cs.json +6 -5
- package/dist/localization/package.nls.de.json +9 -8
- package/dist/localization/package.nls.es.json +6 -5
- package/dist/localization/package.nls.fr.json +6 -5
- package/dist/localization/package.nls.it.json +6 -5
- package/dist/localization/package.nls.ja.json +6 -5
- package/dist/localization/package.nls.ko.json +6 -5
- package/dist/localization/package.nls.pl.json +5 -4
- package/dist/localization/package.nls.pt-br.json +6 -5
- package/dist/localization/package.nls.qps-ploc.json +4 -3
- package/dist/localization/package.nls.ru.json +5 -4
- package/dist/localization/package.nls.tr.json +6 -5
- package/dist/localization/package.nls.zh-cn.json +6 -5
- package/dist/localization/package.nls.zh-tw.json +6 -5
- package/dist/tests/pathUtils.test.js +25 -3
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/package.json +1 -1
@@ -82,6 +82,7 @@ export declare class Checker extends ParseTreeWalker {
|
|
82
82
|
private _validateComparisonTypesForIsOperator;
|
83
83
|
private _validateComparisonTypes;
|
84
84
|
private _isTypeComparable;
|
85
|
+
private _validateGeneratorReturnType;
|
85
86
|
private _isTypeValidForUnusedValueTest;
|
86
87
|
private _validateFunctionTypeVarUsage;
|
87
88
|
private _validateOverloadConsistency;
|
package/dist/analyzer/checker.js
CHANGED
@@ -358,6 +358,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
358
358
|
// Verify TypeGuard functions.
|
359
359
|
this._validateTypeGuardFunction(node, functionTypeResult.functionType, containingClassNode !== undefined);
|
360
360
|
this._validateFunctionTypeVarUsage(node, functionTypeResult);
|
361
|
+
this._validateGeneratorReturnType(node, functionTypeResult.functionType);
|
361
362
|
}
|
362
363
|
// If we're at the module level within a stub file, report a diagnostic
|
363
364
|
// if there is a '__getattr__' function defined when in strict mode.
|
@@ -723,7 +724,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
723
724
|
const baseType = this._evaluator.getType(node.baseExpression);
|
724
725
|
if (baseType) {
|
725
726
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
726
|
-
if ((0, types_1.isClassInstance)(subtype) &&
|
727
|
+
if ((0, types_1.isClassInstance)(subtype) &&
|
728
|
+
subtype.tupleTypeArguments &&
|
729
|
+
!(0, typeUtils_1.isUnboundedTupleClass)(subtype) &&
|
730
|
+
!this._evaluator.isTypeSubsumedByOtherType(subtype, baseType, /* allowAnyToSubsume */ false)) {
|
727
731
|
const tupleLength = subtype.tupleTypeArguments.length;
|
728
732
|
if (node.items.length === 1 &&
|
729
733
|
!node.trailingComma &&
|
@@ -1412,6 +1416,49 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1412
1416
|
}
|
1413
1417
|
return true;
|
1414
1418
|
}
|
1419
|
+
// If the function is a generator, validates that its annotated return type
|
1420
|
+
// is appropriate for a generator.
|
1421
|
+
_validateGeneratorReturnType(node, functionType) {
|
1422
|
+
var _a;
|
1423
|
+
if (!types_1.FunctionType.isGenerator(functionType)) {
|
1424
|
+
return;
|
1425
|
+
}
|
1426
|
+
const declaredReturnType = functionType.details.declaredReturnType;
|
1427
|
+
if (!declaredReturnType) {
|
1428
|
+
return;
|
1429
|
+
}
|
1430
|
+
if ((0, types_1.isNever)(declaredReturnType)) {
|
1431
|
+
return;
|
1432
|
+
}
|
1433
|
+
const functionDecl = functionType.details.declaration;
|
1434
|
+
if (!functionDecl || !functionDecl.yieldStatements || functionDecl.yieldStatements.length === 0) {
|
1435
|
+
return;
|
1436
|
+
}
|
1437
|
+
let generatorType;
|
1438
|
+
if (!node.isAsync &&
|
1439
|
+
(0, types_1.isClassInstance)(declaredReturnType) &&
|
1440
|
+
types_1.ClassType.isBuiltIn(declaredReturnType, 'AwaitableGenerator')) {
|
1441
|
+
// Handle the old-style (pre-await) generator case
|
1442
|
+
// if the return type explicitly uses AwaitableGenerator.
|
1443
|
+
generatorType = this._evaluator.getTypingType(node, 'AwaitableGenerator');
|
1444
|
+
}
|
1445
|
+
else {
|
1446
|
+
generatorType = this._evaluator.getTypingType(node, node.isAsync ? 'AsyncGenerator' : 'Generator');
|
1447
|
+
}
|
1448
|
+
if (!generatorType || !(0, types_1.isInstantiableClass)(generatorType)) {
|
1449
|
+
return;
|
1450
|
+
}
|
1451
|
+
const specializedGenerator = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, [types_1.AnyType.create(), types_1.AnyType.create(), types_1.AnyType.create()],
|
1452
|
+
/* isTypeArgumentExplicit */ true));
|
1453
|
+
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
1454
|
+
if (!this._evaluator.assignType(declaredReturnType, specializedGenerator, diagAddendum)) {
|
1455
|
+
const errorMessage = node.isAsync
|
1456
|
+
? localize_1.Localizer.Diagnostic.generatorAsyncReturnType()
|
1457
|
+
: localize_1.Localizer.Diagnostic.generatorSyncReturnType();
|
1458
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, errorMessage.format({ yieldType: this._evaluator.printType(types_1.AnyType.create()) }) +
|
1459
|
+
diagAddendum.getString(), (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : node.name);
|
1460
|
+
}
|
1461
|
+
}
|
1415
1462
|
// Determines whether the specified type is one that should trigger
|
1416
1463
|
// an "unused" value diagnostic.
|
1417
1464
|
_isTypeValidForUnusedValueTest(type) {
|
@@ -2375,6 +2422,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2375
2422
|
arg0Type = (0, typeUtils_1.mapSubtypes)(arg0Type, (subtype) => {
|
2376
2423
|
return (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2377
2424
|
});
|
2425
|
+
arg0Type = this._evaluator.expandPromotionTypes(node, arg0Type);
|
2378
2426
|
const arg1Type = this._evaluator.getType(node.arguments[1].valueExpression);
|
2379
2427
|
if (!arg1Type) {
|
2380
2428
|
return;
|
@@ -2491,7 +2539,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2491
2539
|
const filteredTypes = [];
|
2492
2540
|
for (const filterType of classTypeList) {
|
2493
2541
|
const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, filterType, filterType, isInstanceCheck);
|
2494
|
-
const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType,
|
2542
|
+
const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, isInstanceCheck);
|
2495
2543
|
// Normally, a class should never be both a subclass and a
|
2496
2544
|
// superclass. However, this can happen if one of the classes
|
2497
2545
|
// derives from an unknown type. In this case, we'll add an
|
@@ -4126,7 +4174,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4126
4174
|
const primaryDecl = decls[0];
|
4127
4175
|
// Verify that the override type is assignable to (same or narrower than)
|
4128
4176
|
// the declared type of the base symbol.
|
4129
|
-
|
4177
|
+
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !primaryDecl.isFinal;
|
4178
|
+
// If the entry is a member of a frozen dataclass, it is immutable,
|
4179
|
+
// so it does not need to be invariant.
|
4180
|
+
if (types_1.ClassType.isFrozenDataClass(baseClassAndSymbol.classType) &&
|
4181
|
+
baseClassAndSymbol.classType.details.dataClassEntries) {
|
4182
|
+
const dataclassEntry = baseClassAndSymbol.classType.details.dataClassEntries.find((entry) => entry.name === memberName);
|
4183
|
+
if (dataclassEntry) {
|
4184
|
+
isInvariant = false;
|
4185
|
+
}
|
4186
|
+
}
|
4130
4187
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4131
4188
|
if (!this._evaluator.assignType(baseType, overrideType, diagAddendum,
|
4132
4189
|
/* destTypeVarContext */ undefined,
|