@zzzen/pyright-internal 1.2.0-dev.20240922 → 1.2.0-dev.20240929
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/binder.d.ts +1 -0
- package/dist/analyzer/binder.js +19 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +0 -1
- package/dist/analyzer/checker.js +68 -82
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/commentUtils.js +2 -2
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +3 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +14 -6
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/importResolver.js +1 -1
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +42 -28
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +4 -4
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/patternMatching.js +7 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/service.js +24 -10
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +5 -3
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -0
- package/dist/analyzer/symbol.js +6 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +5 -5
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +147 -100
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.js +7 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +16 -12
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +16 -4
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +7 -3
- package/dist/analyzer/types.js +6 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +3 -1
- package/dist/common/configOptions.js +17 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/fileSystem.d.ts +8 -1
- package/dist/common/fileSystem.js +10 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/memUtils.js +3 -0
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -3
- package/dist/common/realFileSystem.js +2 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +9 -7
- package/dist/languageService/autoImporter.js +32 -34
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +1 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +1 -1
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/hoverProvider.js +3 -2
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +8 -1
- package/dist/languageService/symbolIndexer.js +17 -2
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/localization/localize.d.ts +1 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +2 -2
- package/dist/localization/package.nls.de.json +2 -2
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +2 -2
- package/dist/localization/package.nls.fr.json +2 -2
- package/dist/localization/package.nls.it.json +2 -2
- package/dist/localization/package.nls.ja.json +2 -2
- package/dist/localization/package.nls.ko.json +2 -2
- package/dist/localization/package.nls.pl.json +2 -2
- package/dist/localization/package.nls.pt-br.json +2 -2
- package/dist/localization/package.nls.ru.json +2 -2
- package/dist/localization/package.nls.tr.json +2 -2
- package/dist/localization/package.nls.zh-cn.json +2 -2
- package/dist/localization/package.nls.zh-tw.json +2 -2
- package/dist/readonlyAugmentedFileSystem.js +2 -1
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +0 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +1 -2
- package/dist/tests/harness/fourslash/testState.js +0 -7
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +8 -3
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +2 -2
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +6 -0
- 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/typeEvaluator6.test.js +6 -2
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +7 -1
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +8 -8
package/dist/analyzer/checker.js
CHANGED
@@ -803,7 +803,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
803
803
|
else if (node.d.operator === 39 /* OperatorType.Is */ || node.d.operator === 40 /* OperatorType.IsNot */) {
|
804
804
|
// Don't apply this rule if it's within an assert.
|
805
805
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
806
|
-
this.
|
806
|
+
this._validateComparisonTypes(node);
|
807
807
|
}
|
808
808
|
}
|
809
809
|
else if (node.d.operator === 41 /* OperatorType.In */ || node.d.operator === 42 /* OperatorType.NotIn */) {
|
@@ -1326,36 +1326,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1326
1326
|
}), node);
|
1327
1327
|
}
|
1328
1328
|
}
|
1329
|
-
// Determines whether the types of the two operands for an "is" or "is not"
|
1330
|
-
// operation have overlapping types.
|
1331
|
-
_validateComparisonTypesForIsOperator(node) {
|
1332
|
-
const rightType = this._evaluator.getType(node.d.rightExpr);
|
1333
|
-
if (!rightType || !(0, typeUtils_1.isNoneInstance)(rightType)) {
|
1334
|
-
return;
|
1335
|
-
}
|
1336
|
-
const leftType = this._evaluator.getType(node.d.leftExpr);
|
1337
|
-
if (!leftType) {
|
1338
|
-
return;
|
1339
|
-
}
|
1340
|
-
let foundMatchForNone = false;
|
1341
|
-
(0, typeUtils_1.doForEachSubtype)(leftType, (subtype) => {
|
1342
|
-
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
1343
|
-
if (this._evaluator.assignType(subtype, this._evaluator.getNoneType())) {
|
1344
|
-
foundMatchForNone = true;
|
1345
|
-
}
|
1346
|
-
});
|
1347
|
-
const getMessage = () => {
|
1348
|
-
return node.d.operator === 39 /* OperatorType.Is */
|
1349
|
-
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1350
|
-
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1351
|
-
};
|
1352
|
-
if (!foundMatchForNone) {
|
1353
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnnecessaryComparison, getMessage().format({
|
1354
|
-
leftType: this._evaluator.printType(leftType, { expandTypeAlias: true }),
|
1355
|
-
rightType: this._evaluator.printType(rightType),
|
1356
|
-
}), node);
|
1357
|
-
}
|
1358
|
-
}
|
1359
1329
|
// Determines whether the types of the two operands for an == or != operation
|
1360
1330
|
// have overlapping types.
|
1361
1331
|
_validateComparisonTypes(node) {
|
@@ -1376,7 +1346,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1376
1346
|
return;
|
1377
1347
|
}
|
1378
1348
|
const getMessage = () => {
|
1379
|
-
return node.d.operator === 12 /* OperatorType.Equals */
|
1349
|
+
return node.d.operator === 12 /* OperatorType.Equals */ || node.d.operator === 39 /* OperatorType.Is */
|
1380
1350
|
? localize_1.LocMessage.comparisonAlwaysFalse()
|
1381
1351
|
: localize_1.LocMessage.comparisonAlwaysTrue();
|
1382
1352
|
};
|
@@ -1404,20 +1374,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1404
1374
|
}
|
1405
1375
|
else {
|
1406
1376
|
let isComparable = false;
|
1407
|
-
|
1377
|
+
this._evaluator.mapSubtypesExpandTypeVars(leftType, {}, (leftSubtype) => {
|
1408
1378
|
if (isComparable) {
|
1409
1379
|
return;
|
1410
1380
|
}
|
1411
|
-
|
1412
|
-
(0, typeUtils_1.doForEachSubtype)(rightType, (rightSubtype) => {
|
1381
|
+
this._evaluator.mapSubtypesExpandTypeVars(rightType, {}, (rightSubtype) => {
|
1413
1382
|
if (isComparable) {
|
1414
1383
|
return;
|
1415
1384
|
}
|
1416
|
-
rightSubtype = this._evaluator.makeTopLevelTypeVarsConcrete(rightSubtype);
|
1417
1385
|
if (this._isTypeComparable(leftSubtype, rightSubtype)) {
|
1418
1386
|
isComparable = true;
|
1419
1387
|
}
|
1388
|
+
return rightSubtype;
|
1420
1389
|
});
|
1390
|
+
return leftSubtype;
|
1421
1391
|
});
|
1422
1392
|
if (!isComparable) {
|
1423
1393
|
const leftTypeText = this._evaluator.printType(leftType, { expandTypeAlias: true });
|
@@ -1440,10 +1410,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1440
1410
|
return false;
|
1441
1411
|
}
|
1442
1412
|
if ((0, types_1.isModule)(leftType) || (0, types_1.isModule)(rightType)) {
|
1443
|
-
return (0, types_1.isTypeSame)(leftType, rightType);
|
1444
|
-
}
|
1445
|
-
if ((0, typeUtils_1.isNoneInstance)(leftType) || (0, typeUtils_1.isNoneInstance)(rightType)) {
|
1446
|
-
return (0, types_1.isTypeSame)(leftType, rightType);
|
1413
|
+
return (0, types_1.isTypeSame)(leftType, rightType, { ignoreConditions: true });
|
1447
1414
|
}
|
1448
1415
|
const isLeftCallable = (0, types_1.isFunction)(leftType) || (0, types_1.isOverloaded)(leftType);
|
1449
1416
|
const isRightCallable = (0, types_1.isFunction)(rightType) || (0, types_1.isOverloaded)(rightType);
|
@@ -1470,7 +1437,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1470
1437
|
return false;
|
1471
1438
|
}
|
1472
1439
|
if ((0, types_1.isClassInstance)(leftType)) {
|
1473
|
-
if ((0, types_1.
|
1440
|
+
if ((0, types_1.isClass)(rightType)) {
|
1474
1441
|
const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
|
1475
1442
|
const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
|
1476
1443
|
if (this._evaluator.assignType(genericLeftType, genericRightType) ||
|
@@ -1479,7 +1446,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1479
1446
|
}
|
1480
1447
|
// Assume that if the types are disjoint and built-in classes that they
|
1481
1448
|
// will never be comparable.
|
1482
|
-
if (types_1.ClassType.isBuiltIn(leftType) && types_1.ClassType.isBuiltIn(rightType)) {
|
1449
|
+
if (types_1.ClassType.isBuiltIn(leftType) && types_1.ClassType.isBuiltIn(rightType) && types_1.TypeBase.isInstance(rightType)) {
|
1483
1450
|
return false;
|
1484
1451
|
}
|
1485
1452
|
}
|
@@ -1586,7 +1553,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1586
1553
|
// the TypeVar multiple times.
|
1587
1554
|
const baseType = this._evaluator.getType(baseExpression);
|
1588
1555
|
const aliasInfo = (_a = baseType === null || baseType === void 0 ? void 0 : baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1589
|
-
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) && subscriptIndex < aliasInfo.typeParams.length) {
|
1556
|
+
if ((aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.shared.typeParams) && subscriptIndex < aliasInfo.shared.typeParams.length) {
|
1590
1557
|
isExempt = true;
|
1591
1558
|
}
|
1592
1559
|
}
|
@@ -3033,7 +3000,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3033
3000
|
const deprecatedForm = (_a = deprecatedSymbols_1.deprecatedAliases.get(node.d.value)) !== null && _a !== void 0 ? _a : deprecatedSymbols_1.deprecatedSpecialForms.get(node.d.value);
|
3034
3001
|
if (deprecatedForm) {
|
3035
3002
|
if (((0, types_1.isInstantiableClass)(type) && type.shared.fullName === deprecatedForm.fullName) ||
|
3036
|
-
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.fullName) === deprecatedForm.fullName) {
|
3003
|
+
((_c = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) === null || _c === void 0 ? void 0 : _c.shared.fullName) === deprecatedForm.fullName) {
|
3037
3004
|
if (pythonVersion_1.PythonVersion.isGreaterOrEqualTo(this._fileInfo.executionEnvironment.pythonVersion, deprecatedForm.version)) {
|
3038
3005
|
if (!deprecatedForm.typingImportOnly || isImportFromTyping) {
|
3039
3006
|
this._reportDeprecatedDiagnostic(node, localize_1.LocMessage.deprecatedType().format({
|
@@ -4877,7 +4844,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4877
4844
|
['fdel', (c) => { var _a; return (_a = c.priv.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4878
4845
|
];
|
4879
4846
|
propMethodInfo.forEach((info) => {
|
4880
|
-
var _a;
|
4847
|
+
var _a, _b;
|
4881
4848
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4882
4849
|
const [methodName, methodAccessor] = info;
|
4883
4850
|
const baseClassPropMethod = methodAccessor(baseType);
|
@@ -4885,46 +4852,65 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4885
4852
|
// Is the method present on the base class but missing in the subclass?
|
4886
4853
|
if (baseClassPropMethod) {
|
4887
4854
|
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType, this._evaluator.getTypeClassType());
|
4888
|
-
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4893
|
-
|
4894
|
-
|
4895
|
-
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4901
|
-
|
4902
|
-
|
4903
|
-
|
4904
|
-
|
4855
|
+
if (!(0, types_1.isFunction)(baseClassMethodType)) {
|
4856
|
+
return;
|
4857
|
+
}
|
4858
|
+
if (!subclassPropMethod) {
|
4859
|
+
// The method is missing.
|
4860
|
+
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodMissing().format({
|
4861
|
+
name: methodName,
|
4862
|
+
}));
|
4863
|
+
const decls = overrideSymbol.getDeclarations();
|
4864
|
+
if (decls.length > 0) {
|
4865
|
+
const lastDecl = decls[decls.length - 1];
|
4866
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4867
|
+
name: memberName,
|
4868
|
+
className: baseClassType.shared.name,
|
4869
|
+
}) + diagAddendum.getString(), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(lastDecl)) !== null && _a !== void 0 ? _a : lastDecl.node);
|
4870
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4871
|
+
if (diag && origDecl) {
|
4872
|
+
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4905
4873
|
}
|
4906
4874
|
}
|
4907
|
-
|
4908
|
-
|
4909
|
-
|
4910
|
-
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
|
4919
|
-
|
4920
|
-
|
4921
|
-
|
4922
|
-
|
4923
|
-
|
4924
|
-
|
4925
|
-
|
4926
|
-
|
4875
|
+
return;
|
4876
|
+
}
|
4877
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType, this._evaluator.getTypeClassType());
|
4878
|
+
if (!(0, types_1.isFunction)(subclassMethodType)) {
|
4879
|
+
return;
|
4880
|
+
}
|
4881
|
+
if (this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, childClassType, diagAddendum.createAddendum())) {
|
4882
|
+
return;
|
4883
|
+
}
|
4884
|
+
diagAddendum.addMessage(localize_1.LocAddendum.propertyMethodIncompatible().format({
|
4885
|
+
name: methodName,
|
4886
|
+
}));
|
4887
|
+
const decl = subclassMethodType.shared.declaration;
|
4888
|
+
if (!decl || decl.type !== 5 /* DeclarationType.Function */) {
|
4889
|
+
return;
|
4890
|
+
}
|
4891
|
+
let diagLocation = decl.node.d.name;
|
4892
|
+
// Make sure the method decl is contained within the
|
4893
|
+
// class suite. If not, it probably comes from a decorator
|
4894
|
+
// in another class. We don't want to report the error
|
4895
|
+
// in the wrong location.
|
4896
|
+
const childClassDecl = childClassType.shared.declaration;
|
4897
|
+
if (!childClassDecl ||
|
4898
|
+
childClassDecl.node.nodeType !== 10 /* ParseNodeType.Class */ ||
|
4899
|
+
!ParseTreeUtils.isNodeContainedWithin(decl.node, childClassDecl.node.d.suite)) {
|
4900
|
+
const symbolDecls = overrideSymbol.getDeclarations();
|
4901
|
+
if (symbolDecls.length === 0) {
|
4902
|
+
return;
|
4927
4903
|
}
|
4904
|
+
const lastSymbolDecl = symbolDecls[symbolDecls.length - 1];
|
4905
|
+
diagLocation = (_b = (0, declarationUtils_1.getNameNodeForDeclaration)(lastSymbolDecl)) !== null && _b !== void 0 ? _b : lastSymbolDecl.node;
|
4906
|
+
}
|
4907
|
+
const diag = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
|
4908
|
+
name: memberName,
|
4909
|
+
className: baseClassType.shared.name,
|
4910
|
+
}) + diagAddendum.getString(), diagLocation);
|
4911
|
+
const origDecl = baseClassMethodType.shared.declaration;
|
4912
|
+
if (diag && origDecl) {
|
4913
|
+
diag.addRelatedInfo(localize_1.LocAddendum.overriddenMethod(), origDecl.uri, origDecl.range);
|
4928
4914
|
}
|
4929
4915
|
}
|
4930
4916
|
});
|