@zzzen/pyright-internal 1.2.0-dev.20240901 → 1.2.0-dev.20240908
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.js +14 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +23 -41
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +7 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +7 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/namedTuples.js +4 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +5 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +1 -1
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/protocols.js +5 -8
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +2 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +536 -155
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +11 -8
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -1
- package/dist/analyzer/typePrinter.js +24 -4
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -0
- package/dist/analyzer/typeUtils.js +54 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +8 -4
- package/dist/analyzer/types.js +68 -26
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +2 -1
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +12 -12
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +6 -6
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +9 -9
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -0
- package/dist/languageService/hoverProvider.js +30 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -2
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +2 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -0
- package/dist/parser/parseNodes.d.ts +2 -3
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +6 -20
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +5 -1
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +1 -1
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +6 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +40 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/workspaceFactory.js +7 -7
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/checker.js
CHANGED
@@ -412,7 +412,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
412
412
|
}
|
413
413
|
}
|
414
414
|
this._scopedNodes.push(node);
|
415
|
-
if (functionTypeResult &&
|
415
|
+
if (functionTypeResult &&
|
416
|
+
(0, types_1.isOverloaded)(functionTypeResult.decoratedType) &&
|
417
|
+
functionTypeResult.functionType.priv.overloaded) {
|
416
418
|
// If this is the implementation for the overloaded function, skip
|
417
419
|
// overload consistency checks.
|
418
420
|
if (types_1.OverloadedType.getImplementation(functionTypeResult.decoratedType) !== functionTypeResult.functionType) {
|
@@ -672,34 +674,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
672
674
|
return true;
|
673
675
|
}
|
674
676
|
visitRaise(node) {
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
if (exceptionType && baseExceptionType && (0, types_1.isInstantiableClass)(baseExceptionType)) {
|
681
|
-
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
682
|
-
(0, typeUtils_1.doForEachSubtype)(exceptionType, (subtype) => {
|
683
|
-
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
684
|
-
if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, typeUtils_1.isNoneInstance)(subtype)) {
|
685
|
-
if ((0, types_1.isClass)(subtype)) {
|
686
|
-
if (!(0, typeUtils_1.derivesFromClassRecursive)(subtype, baseExceptionType, /* ignoreUnknown */ false)) {
|
687
|
-
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
688
|
-
type: this._evaluator.printType(subtype),
|
689
|
-
}));
|
690
|
-
}
|
691
|
-
}
|
692
|
-
else {
|
693
|
-
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
|
694
|
-
type: this._evaluator.printType(subtype),
|
695
|
-
}));
|
696
|
-
}
|
697
|
-
}
|
698
|
-
});
|
699
|
-
if (!diagAddendum.isEmpty()) {
|
700
|
-
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.d.valueExpression);
|
701
|
-
}
|
702
|
-
}
|
677
|
+
if (node.d.expr) {
|
678
|
+
this._evaluator.verifyRaiseExceptionType(node.d.expr);
|
679
|
+
}
|
680
|
+
if (node.d.fromExpr) {
|
681
|
+
this._evaluator.verifyRaiseExceptionType(node.d.fromExpr);
|
703
682
|
}
|
704
683
|
return true;
|
705
684
|
}
|
@@ -1009,11 +988,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1009
988
|
return true;
|
1010
989
|
}
|
1011
990
|
visitImportFromAs(node) {
|
1012
|
-
var _a, _b;
|
991
|
+
var _a, _b, _c;
|
1013
992
|
if (this._fileInfo.isStubFile) {
|
1014
993
|
return false;
|
1015
994
|
}
|
1016
|
-
const decls = this._evaluator.
|
995
|
+
const decls = (_a = this._evaluator.getDeclInfoForNameNode(node.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
|
1017
996
|
if (!decls) {
|
1018
997
|
return false;
|
1019
998
|
}
|
@@ -1035,14 +1014,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1035
1014
|
break;
|
1036
1015
|
}
|
1037
1016
|
let isImportFromTyping = false;
|
1038
|
-
if (((
|
1017
|
+
if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 25 /* ParseNodeType.ImportFrom */) {
|
1039
1018
|
if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
|
1040
1019
|
if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
|
1041
1020
|
isImportFromTyping = true;
|
1042
1021
|
}
|
1043
1022
|
}
|
1044
1023
|
}
|
1045
|
-
const type = this._evaluator.getType((
|
1024
|
+
const type = this._evaluator.getType((_c = node.d.alias) !== null && _c !== void 0 ? _c : node.d.name);
|
1046
1025
|
this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
|
1047
1026
|
return false;
|
1048
1027
|
}
|
@@ -1851,7 +1830,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1851
1830
|
// earlier overload. Typeshed stubs contain type: ignore comments on these
|
1852
1831
|
// lines, so it is important for us to report them in the same manner.
|
1853
1832
|
_findNodeForOverload(functionNode, overloadType) {
|
1854
|
-
|
1833
|
+
var _a;
|
1834
|
+
const decls = (_a = this._evaluator.getDeclInfoForNameNode(functionNode.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
|
1855
1835
|
if (!decls) {
|
1856
1836
|
return undefined;
|
1857
1837
|
}
|
@@ -3306,7 +3286,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3306
3286
|
}
|
3307
3287
|
}
|
3308
3288
|
_conditionallyReportPrivateUsage(node) {
|
3309
|
-
var _a, _b;
|
3289
|
+
var _a, _b, _c;
|
3310
3290
|
if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
|
3311
3291
|
return;
|
3312
3292
|
}
|
@@ -3329,8 +3309,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3329
3309
|
// Get the declarations for this name node, but filter out
|
3330
3310
|
// any variable declarations that are bound using nonlocal
|
3331
3311
|
// or global explicit bindings.
|
3332
|
-
const declarations = (_b = this._evaluator
|
3333
|
-
.
|
3312
|
+
const declarations = (_c = (_b = this._evaluator
|
3313
|
+
.getDeclInfoForNameNode(node)) === null || _b === void 0 ? void 0 : _b.decls) === null || _c === void 0 ? void 0 : _c.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
|
3334
3314
|
let primaryDeclaration = declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
|
3335
3315
|
if (!primaryDeclaration || primaryDeclaration.node === node) {
|
3336
3316
|
return;
|
@@ -3465,7 +3445,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3465
3445
|
}
|
3466
3446
|
if (isTypeIs) {
|
3467
3447
|
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(functionType);
|
3468
|
-
const
|
3448
|
+
const narrowedType = returnType.priv.typeArgs[0];
|
3449
|
+
let typeGuardType = (0, typeUtils_1.makeTypeVarsBound)(narrowedType, scopeIds);
|
3450
|
+
typeGuardType = types_1.TypeBase.cloneWithTypeForm(typeGuardType, typeGuardType);
|
3469
3451
|
// Determine the type of the first parameter.
|
3470
3452
|
const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
|
3471
3453
|
if (paramIndex >= functionType.shared.parameters.length) {
|
@@ -3478,7 +3460,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3478
3460
|
if (returnAnnotation) {
|
3479
3461
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
|
3480
3462
|
type: this._evaluator.printType(paramType),
|
3481
|
-
returnType: this._evaluator.printType(
|
3463
|
+
returnType: this._evaluator.printType(narrowedType),
|
3482
3464
|
}), returnAnnotation);
|
3483
3465
|
}
|
3484
3466
|
}
|
@@ -3604,7 +3586,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3604
3586
|
className: parentSymbol.classType.shared.name,
|
3605
3587
|
}), decl.node);
|
3606
3588
|
}
|
3607
|
-
else if (types_1.ClassType.
|
3589
|
+
else if (types_1.ClassType.hasNamedTupleEntry(parentSymbol.classType, name) &&
|
3608
3590
|
!SymbolNameUtils.isDunderName(name)) {
|
3609
3591
|
// If the parent class is a named tuple, all instance variables
|
3610
3592
|
// (other than dundered ones) are implicitly final.
|
@@ -3893,7 +3875,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3893
3875
|
// If this is part of a dataclass, a class handled by a dataclass_transform,
|
3894
3876
|
// or a NamedTuple, exempt it because the class variable will be transformed
|
3895
3877
|
// into an instance variable in this case.
|
3896
|
-
if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.
|
3878
|
+
if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.hasNamedTupleEntry(classType, name)) {
|
3897
3879
|
return true;
|
3898
3880
|
}
|
3899
3881
|
// If this is part of a TypedDict, exempt it because the class variables
|