@zzzen/pyright-internal 1.2.0-dev.20240428 → 1.2.0-dev.20240512
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/analyzerFileInfo.js +3 -2
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/binder.js +6 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +62 -35
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -0
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/operations.js +3 -2
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/patternMatching.js +20 -14
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/scope.d.ts +4 -0
- package/dist/analyzer/scope.js +9 -2
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/sourceFile.js +13 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +56 -17
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +38 -19
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +1 -5
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/envVarUtils.js +1 -2
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +1 -0
- package/dist/common/pythonVersion.js +2 -1
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -2
- package/dist/languageServerBase.js +13 -35
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +1 -1
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/dynamicFeature.d.ts +18 -0
- package/dist/languageService/dynamicFeature.js +54 -0
- package/dist/languageService/dynamicFeature.js.map +1 -0
- package/dist/languageService/fileWatcherDynamicFeature.d.ts +12 -0
- package/dist/languageService/fileWatcherDynamicFeature.js +49 -0
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -0
- package/dist/localization/package.nls.cs.json +28 -26
- package/dist/localization/package.nls.de.json +28 -26
- package/dist/localization/package.nls.en-us.json +2 -2
- package/dist/localization/package.nls.es.json +27 -25
- package/dist/localization/package.nls.fr.json +28 -26
- package/dist/localization/package.nls.it.json +28 -26
- package/dist/localization/package.nls.ja.json +28 -26
- package/dist/localization/package.nls.ko.json +28 -26
- package/dist/localization/package.nls.pl.json +27 -25
- package/dist/localization/package.nls.pt-br.json +28 -26
- package/dist/localization/package.nls.qps-ploc.json +25 -23
- package/dist/localization/package.nls.ru.json +28 -26
- package/dist/localization/package.nls.tr.json +28 -26
- package/dist/localization/package.nls.zh-cn.json +28 -26
- package/dist/localization/package.nls.zh-tw.json +28 -26
- package/dist/parser/tokenizer.js +7 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +20 -0
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +7 -2
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +59 -479
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -486
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +0 -604
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -423
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.d.ts +1 -0
- package/dist/tests/typeEvaluator6.test.js +712 -0
- package/dist/tests/typeEvaluator6.test.js.map +1 -0
- package/dist/tests/typeEvaluator7.test.d.ts +1 -0
- package/dist/tests/typeEvaluator7.test.js +677 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -0
- package/dist/tests/typeEvaluator8.test.d.ts +1 -0
- package/dist/tests/typeEvaluator8.test.js +660 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -0
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -767,31 +767,37 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
767
767
|
if (baseType) {
|
768
768
|
(0, typeUtils_1.doForEachSubtype)(baseType, (subtype) => {
|
769
769
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
770
|
-
if ((0, types_1.isClassInstance)(subtype)
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
}
|
792
|
-
}
|
793
|
-
}
|
770
|
+
if (!(0, types_1.isClassInstance)(subtype) || !(tupleType === null || tupleType === void 0 ? void 0 : tupleType.tupleTypeArguments) || (0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
771
|
+
return;
|
772
|
+
}
|
773
|
+
const tupleLength = tupleType.tupleTypeArguments.length;
|
774
|
+
if (node.items.length !== 1 ||
|
775
|
+
node.trailingComma ||
|
776
|
+
node.items[0].argumentCategory !== 0 /* ArgumentCategory.Simple */ ||
|
777
|
+
node.items[0].name) {
|
778
|
+
return;
|
779
|
+
}
|
780
|
+
const subscriptType = this._evaluator.getType(node.items[0].valueExpression);
|
781
|
+
if (!subscriptType ||
|
782
|
+
!(0, types_1.isClassInstance)(subscriptType) ||
|
783
|
+
!types_1.ClassType.isBuiltIn(subscriptType, 'int') ||
|
784
|
+
!(0, typeUtils_1.isLiteralType)(subscriptType) ||
|
785
|
+
typeof subscriptType.literalValue !== 'number') {
|
786
|
+
return;
|
787
|
+
}
|
788
|
+
if ((subscriptType.literalValue < 0 || subscriptType.literalValue < tupleLength) &&
|
789
|
+
(subscriptType.literalValue >= 0 || subscriptType.literalValue + tupleLength >= 0)) {
|
790
|
+
return;
|
794
791
|
}
|
792
|
+
// This can be an expensive check, so we save it for the end once we
|
793
|
+
// are about to emit a diagnostic.
|
794
|
+
if (this._evaluator.isTypeSubsumedByOtherType(tupleType, baseType, /* allowAnyToSubsume */ false)) {
|
795
|
+
return;
|
796
|
+
}
|
797
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.tupleIndexOutOfRange().format({
|
798
|
+
index: subscriptType.literalValue,
|
799
|
+
type: this._evaluator.printType(subtype),
|
800
|
+
}), node);
|
795
801
|
});
|
796
802
|
}
|
797
803
|
return true;
|
@@ -1196,14 +1202,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1196
1202
|
}
|
1197
1203
|
const exprTypeResult = this._evaluator.getTypeOfExpression(expression);
|
1198
1204
|
let isExprFunction = true;
|
1199
|
-
let isCoroutine =
|
1205
|
+
let isCoroutine = true;
|
1200
1206
|
(0, typeUtils_1.doForEachSubtype)(exprTypeResult.type, (subtype) => {
|
1201
1207
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
1202
1208
|
if (!(0, types_1.isFunction)(subtype) && !(0, types_1.isOverloadedFunction)(subtype)) {
|
1203
1209
|
isExprFunction = false;
|
1204
1210
|
}
|
1205
|
-
if ((0, types_1.isClassInstance)(subtype)
|
1206
|
-
isCoroutine =
|
1211
|
+
if (!(0, types_1.isClassInstance)(subtype) || !types_1.ClassType.isBuiltIn(subtype, 'Coroutine')) {
|
1212
|
+
isCoroutine = false;
|
1207
1213
|
}
|
1208
1214
|
});
|
1209
1215
|
if (isExprFunction) {
|
@@ -1675,6 +1681,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1675
1681
|
exemptBoundTypeVar = false;
|
1676
1682
|
nameWalker.walk(node.returnTypeAnnotation);
|
1677
1683
|
}
|
1684
|
+
if (node.functionAnnotationComment) {
|
1685
|
+
node.functionAnnotationComment.paramTypeAnnotations.forEach((expr) => {
|
1686
|
+
nameWalker.walk(expr);
|
1687
|
+
});
|
1688
|
+
if (node.functionAnnotationComment.returnTypeAnnotation) {
|
1689
|
+
exemptBoundTypeVar = false;
|
1690
|
+
nameWalker.walk(node.functionAnnotationComment.returnTypeAnnotation);
|
1691
|
+
}
|
1692
|
+
}
|
1678
1693
|
localTypeVarUsage.forEach((usage) => {
|
1679
1694
|
var _a;
|
1680
1695
|
// Report error for local type variable that appears only once.
|
@@ -2153,11 +2168,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2153
2168
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
2154
2169
|
if (decl.inferredTypeSource) {
|
2155
2170
|
if (sawAssignment) {
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2171
|
+
let exemptAssignment = false;
|
2172
|
+
if (scopeType === 3 /* ScopeType.Class */) {
|
2173
|
+
// We check for assignment of Final instance and class variables
|
2174
|
+
// in the type evaluator because we need to take into account whether
|
2175
|
+
// the assignment is within an `__init__` method, so ignore class
|
2176
|
+
// scopes here.
|
2177
|
+
const classOrFunc = ParseTreeUtils.getEnclosingClassOrFunction(decl.node);
|
2178
|
+
if ((classOrFunc === null || classOrFunc === void 0 ? void 0 : classOrFunc.nodeType) === 28 /* ParseNodeType.Function */) {
|
2179
|
+
exemptAssignment = true;
|
2180
|
+
}
|
2181
|
+
}
|
2182
|
+
if (!exemptAssignment) {
|
2161
2183
|
reportRedeclaration = true;
|
2162
2184
|
}
|
2163
2185
|
}
|
@@ -2700,7 +2722,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2700
2722
|
const filterType = (varType) => {
|
2701
2723
|
const filteredTypes = [];
|
2702
2724
|
for (const filterType of classTypeList) {
|
2703
|
-
const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, varType, filterType, filterType, isInstanceCheck
|
2725
|
+
const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, varType, filterType, filterType, isInstanceCheck,
|
2726
|
+
/* isTypeIsCheck */ false);
|
2704
2727
|
const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, isInstanceCheck);
|
2705
2728
|
// Normally, a class should never be both a subclass and a
|
2706
2729
|
// superclass. However, this can happen if one of the classes
|
@@ -3181,7 +3204,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3181
3204
|
}
|
3182
3205
|
}
|
3183
3206
|
_conditionallyReportPrivateUsage(node) {
|
3184
|
-
var _a;
|
3207
|
+
var _a, _b;
|
3185
3208
|
if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
|
3186
3209
|
return;
|
3187
3210
|
}
|
@@ -3201,7 +3224,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3201
3224
|
if (!isPrivateName && !isProtectedName) {
|
3202
3225
|
return;
|
3203
3226
|
}
|
3204
|
-
|
3227
|
+
// Get the declarations for this name node, but filter out
|
3228
|
+
// any variable declarations that are bound using nonlocal
|
3229
|
+
// or global explicit bindings.
|
3230
|
+
const declarations = (_b = this._evaluator
|
3231
|
+
.getDeclarationsForNameNode(node)) === null || _b === void 0 ? void 0 : _b.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
|
3205
3232
|
let primaryDeclaration = declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
|
3206
3233
|
if (!primaryDeclaration || primaryDeclaration.node === node) {
|
3207
3234
|
return;
|