@zzzen/pyright-internal 1.2.0-dev.20241020 → 1.2.0-dev.20241027
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 +61 -37
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -17
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +1 -3
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/operations.js +2 -2
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +4 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/service.js +5 -5
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +8 -3
- package/dist/analyzer/symbol.js +4 -4
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +101 -64
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -5
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +17 -17
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -1
- package/dist/analyzer/typeUtils.js +17 -6
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -1
- package/dist/analyzer/types.js +3 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +4 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +21 -5
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +5 -4
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +10 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +3 -1
- package/dist/localization/package.nls.de.json +2 -0
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +2 -0
- package/dist/localization/package.nls.fr.json +2 -0
- package/dist/localization/package.nls.it.json +3 -1
- package/dist/localization/package.nls.ja.json +2 -0
- package/dist/localization/package.nls.ko.json +2 -0
- package/dist/localization/package.nls.pl.json +2 -0
- package/dist/localization/package.nls.pt-br.json +3 -1
- package/dist/localization/package.nls.qps-ploc.json +3 -1
- package/dist/localization/package.nls.ru.json +3 -1
- package/dist/localization/package.nls.tr.json +2 -0
- package/dist/localization/package.nls.zh-cn.json +2 -0
- package/dist/localization/package.nls.zh-tw.json +3 -1
- package/dist/server.d.ts +1 -2
- package/dist/tests/fourslash/import.multipart2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js +20 -0
- package/dist/tests/fourslash/import.multipart2.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +3 -3
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/package.json +2 -2
@@ -2022,7 +2022,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2022
2022
|
// Handle the case where the type is synthesized (used for
|
2023
2023
|
// dataclasses).
|
2024
2024
|
if (synthesizedType) {
|
2025
|
-
isObjectHashable = !(0, typeUtils_1.isNoneInstance)(synthesizedType);
|
2025
|
+
isObjectHashable = !(0, typeUtils_1.isNoneInstance)(synthesizedType.type);
|
2026
2026
|
}
|
2027
2027
|
else {
|
2028
2028
|
// Assume that if '__hash__' is declared as a variable, it is
|
@@ -7310,13 +7310,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7310
7310
|
// Build a map of parameters by name.
|
7311
7311
|
const paramMap = new Map();
|
7312
7312
|
paramDetails.params.forEach((paramInfo) => {
|
7313
|
+
var _a, _b;
|
7313
7314
|
(0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
|
7314
7315
|
const param = paramInfo.param;
|
7315
7316
|
if (param.name && param.category === 0 /* ParamCategory.Simple */ && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
|
7316
|
-
paramMap.
|
7317
|
-
|
7318
|
-
|
7319
|
-
}
|
7317
|
+
let argsNeeded = (_b = (_a = paramMap.get(param.name)) === null || _a === void 0 ? void 0 : _a.argsNeeded) !== null && _b !== void 0 ? _b : 0;
|
7318
|
+
if (param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType) {
|
7319
|
+
argsNeeded += 1;
|
7320
|
+
}
|
7321
|
+
paramMap.set(param.name, { argsNeeded, argsReceived: 0 });
|
7320
7322
|
}
|
7321
7323
|
});
|
7322
7324
|
let positionalOnlyLimitIndex = paramDetails.positionOnlyParamCount;
|
@@ -8369,11 +8371,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8369
8371
|
if (paramSpec) {
|
8370
8372
|
if (argParam.argument.argCategory === 1 /* ArgCategory.UnpackedList */) {
|
8371
8373
|
if ((0, parameterUtils_1.isParamSpecArgs)(paramSpec, argResult.argType)) {
|
8374
|
+
if (sawParamSpecArgs) {
|
8375
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsKwargsDuplicate().format({ type: printType(paramSpec) }), argParam.errorNode);
|
8376
|
+
}
|
8372
8377
|
sawParamSpecArgs = true;
|
8373
8378
|
}
|
8374
8379
|
}
|
8375
8380
|
if (argParam.argument.argCategory === 2 /* ArgCategory.UnpackedDictionary */) {
|
8376
8381
|
if ((0, parameterUtils_1.isParamSpecKwargs)(paramSpec, argResult.argType)) {
|
8382
|
+
if (sawParamSpecKwargs) {
|
8383
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsKwargsDuplicate().format({ type: printType(paramSpec) }), argParam.errorNode);
|
8384
|
+
}
|
8377
8385
|
sawParamSpecKwargs = true;
|
8378
8386
|
}
|
8379
8387
|
}
|
@@ -15088,15 +15096,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15088
15096
|
// Filter the declarations based on flow reachability.
|
15089
15097
|
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
15090
15098
|
if (decl.type !== 8 /* DeclarationType.Alias */ && decl.type !== 0 /* DeclarationType.Intrinsic */) {
|
15091
|
-
//
|
15092
|
-
|
15099
|
+
// Determine if the declaration is in the same execution scope as the "usageNode" node.
|
15100
|
+
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
15093
15101
|
const declNode = decl.type === 6 /* DeclarationType.Class */ ||
|
15094
15102
|
decl.type === 5 /* DeclarationType.Function */ ||
|
15095
15103
|
decl.type === 4 /* DeclarationType.TypeAlias */
|
15096
15104
|
? decl.node.d.name
|
15097
15105
|
: decl.node;
|
15098
|
-
const
|
15099
|
-
|
15106
|
+
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode);
|
15107
|
+
// If this is a type parameter scope, it will be a proxy for its
|
15108
|
+
// containing scope, so we need to use that instead.
|
15109
|
+
const usageScope = AnalyzerNodeInfo.getScope(usageScopeNode);
|
15110
|
+
if (usageScope === null || usageScope === void 0 ? void 0 : usageScope.proxy) {
|
15111
|
+
const typeParamScope = AnalyzerNodeInfo.getScope(usageScopeNode);
|
15112
|
+
if (!(typeParamScope === null || typeParamScope === void 0 ? void 0 : typeParamScope.symbolTable.has(name)) && usageScopeNode.parent) {
|
15113
|
+
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent);
|
15114
|
+
}
|
15115
|
+
}
|
15116
|
+
if (usageScopeNode === declScopeNode) {
|
15100
15117
|
if (!isFlowPathBetweenNodes(declNode, node)) {
|
15101
15118
|
// If there was no control flow path from the usage back
|
15102
15119
|
// to the source, see if the usage node is reachable by
|
@@ -15303,7 +15320,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15303
15320
|
// dictionary expression where those keys are associated with a known TypedDict.
|
15304
15321
|
function getDeclInfoForStringNode(node) {
|
15305
15322
|
var _a;
|
15306
|
-
const
|
15323
|
+
const decls = [];
|
15324
|
+
const synthesizedTypes = [];
|
15307
15325
|
const expectedType = (_a = getExpectedType(node)) === null || _a === void 0 ? void 0 : _a.type;
|
15308
15326
|
if (expectedType) {
|
15309
15327
|
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
@@ -15317,13 +15335,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15317
15335
|
if (entry) {
|
15318
15336
|
const symbol = (_b = (0, typeUtils_1.lookUpObjectMember)(subtype, node.d.value)) === null || _b === void 0 ? void 0 : _b.symbol;
|
15319
15337
|
if (symbol) {
|
15320
|
-
(0, collectionUtils_1.appendArray)(
|
15338
|
+
(0, collectionUtils_1.appendArray)(decls, symbol.getDeclarations());
|
15339
|
+
const synthTypeInfo = symbol.getSynthesizedType();
|
15340
|
+
if (synthTypeInfo) {
|
15341
|
+
synthesizedTypes.push(synthTypeInfo);
|
15342
|
+
}
|
15321
15343
|
}
|
15322
15344
|
}
|
15323
15345
|
}
|
15324
15346
|
});
|
15325
15347
|
}
|
15326
|
-
return
|
15348
|
+
return decls.length === 0 ? undefined : { decls, synthesizedTypes };
|
15327
15349
|
}
|
15328
15350
|
function getAliasFromImport(node) {
|
15329
15351
|
if (node.parent &&
|
@@ -15339,7 +15361,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15339
15361
|
if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
|
15340
15362
|
return undefined;
|
15341
15363
|
}
|
15342
|
-
const
|
15364
|
+
const decls = [];
|
15343
15365
|
const synthesizedTypes = [];
|
15344
15366
|
// If the node is part of a "from X import Y as Z" statement and the node
|
15345
15367
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
@@ -15356,7 +15378,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15356
15378
|
const declsForThisImport = symbolInScope.symbol.getDeclarations().filter((decl) => {
|
15357
15379
|
return decl.type === 8 /* DeclarationType.Alias */ && decl.node === node.parent;
|
15358
15380
|
});
|
15359
|
-
(0, collectionUtils_1.appendArray)(
|
15381
|
+
(0, collectionUtils_1.appendArray)(decls, (0, declarationUtils_1.getDeclarationsWithUsesLocalNameRemoved)(declsForThisImport));
|
15360
15382
|
}
|
15361
15383
|
}
|
15362
15384
|
}
|
@@ -15407,16 +15429,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15407
15429
|
// which includes every assignment of that symbol.
|
15408
15430
|
const typedDecls = symbol.getTypedDeclarations();
|
15409
15431
|
if (typedDecls.length > 0) {
|
15410
|
-
(0, collectionUtils_1.appendArray)(
|
15432
|
+
(0, collectionUtils_1.appendArray)(decls, typedDecls);
|
15411
15433
|
}
|
15412
15434
|
else {
|
15413
|
-
|
15414
|
-
|
15415
|
-
|
15416
|
-
|
15417
|
-
|
15418
|
-
(0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
|
15419
|
-
}
|
15435
|
+
(0, collectionUtils_1.appendArray)(decls, symbol.getDeclarations());
|
15436
|
+
}
|
15437
|
+
const synthTypeInfo = symbol.getSynthesizedType();
|
15438
|
+
if (synthTypeInfo) {
|
15439
|
+
synthesizedTypes.push(synthTypeInfo);
|
15420
15440
|
}
|
15421
15441
|
}
|
15422
15442
|
});
|
@@ -15434,7 +15454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15434
15454
|
// Synthesize an alias declaration for this name part. The only
|
15435
15455
|
// time this case is used is for IDE services such as
|
15436
15456
|
// the find all references, hover provider and etc.
|
15437
|
-
|
15457
|
+
decls.push((0, declarationUtils_1.synthesizeAliasDeclaration)(importInfo.resolvedUris[namePartIndex]));
|
15438
15458
|
}
|
15439
15459
|
}
|
15440
15460
|
}
|
@@ -15449,14 +15469,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15449
15469
|
if ((0, types_1.isFunction)(baseType) && baseType.shared.declaration) {
|
15450
15470
|
const paramDecl = getDeclarationFromKeywordParam(baseType, paramName);
|
15451
15471
|
if (paramDecl) {
|
15452
|
-
|
15472
|
+
decls.push(paramDecl);
|
15453
15473
|
}
|
15454
15474
|
}
|
15455
15475
|
else if ((0, types_1.isOverloaded)(baseType)) {
|
15456
15476
|
types_1.OverloadedType.getOverloads(baseType).forEach((f) => {
|
15457
15477
|
const paramDecl = getDeclarationFromKeywordParam(f, paramName);
|
15458
15478
|
if (paramDecl) {
|
15459
|
-
|
15479
|
+
decls.push(paramDecl);
|
15460
15480
|
}
|
15461
15481
|
});
|
15462
15482
|
}
|
@@ -15465,14 +15485,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15465
15485
|
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
15466
15486
|
const paramDecl = getDeclarationFromKeywordParam(initMethodType, paramName);
|
15467
15487
|
if (paramDecl) {
|
15468
|
-
|
15488
|
+
decls.push(paramDecl);
|
15469
15489
|
}
|
15470
15490
|
else if (types_1.ClassType.isDataClass(baseType) ||
|
15471
15491
|
types_1.ClassType.isTypedDictClass(baseType) ||
|
15472
15492
|
types_1.ClassType.hasNamedTupleEntry(baseType, paramName)) {
|
15473
15493
|
const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
|
15474
15494
|
if (lookupResults) {
|
15475
|
-
(0, collectionUtils_1.appendArray)(
|
15495
|
+
(0, collectionUtils_1.appendArray)(decls, lookupResults.symbol.getDeclarations());
|
15496
|
+
const synthTypeInfo = lookupResults.symbol.getSynthesizedType();
|
15497
|
+
if (synthTypeInfo) {
|
15498
|
+
synthesizedTypes.push(synthTypeInfo);
|
15499
|
+
}
|
15476
15500
|
}
|
15477
15501
|
}
|
15478
15502
|
}
|
@@ -15497,10 +15521,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15497
15521
|
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
15498
15522
|
const symbolWithScope = lookUpSymbolRecursive(node, node.d.value, !allowForwardReferences, isWithinTypeAnnotation);
|
15499
15523
|
if (symbolWithScope) {
|
15500
|
-
(0, collectionUtils_1.appendArray)(
|
15524
|
+
(0, collectionUtils_1.appendArray)(decls, symbolWithScope.symbol.getDeclarations());
|
15525
|
+
const synthTypeInfo = symbolWithScope.symbol.getSynthesizedType();
|
15526
|
+
if (synthTypeInfo) {
|
15527
|
+
synthesizedTypes.push(synthTypeInfo);
|
15528
|
+
}
|
15501
15529
|
}
|
15502
15530
|
}
|
15503
|
-
return { decls
|
15531
|
+
return { decls, synthesizedTypes };
|
15504
15532
|
}
|
15505
15533
|
function getTypeForDeclaration(declaration) {
|
15506
15534
|
var _a, _b, _c;
|
@@ -16270,7 +16298,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16270
16298
|
// provided, but type inference is still required. In such cases, the attributes
|
16271
16299
|
// are returned as flags.
|
16272
16300
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
16273
|
-
|
16301
|
+
var _a;
|
16302
|
+
const synthesizedType = (_a = symbol.getSynthesizedType()) === null || _a === void 0 ? void 0 : _a.type;
|
16274
16303
|
if (synthesizedType) {
|
16275
16304
|
return { type: synthesizedType };
|
16276
16305
|
}
|
@@ -16884,41 +16913,49 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16884
16913
|
}
|
16885
16914
|
// Now handle generic base classes.
|
16886
16915
|
destType.shared.baseClasses.forEach((baseClass) => {
|
16887
|
-
if (
|
16888
|
-
!types_1.
|
16889
|
-
|
16890
|
-
|
16891
|
-
|
16892
|
-
|
16893
|
-
|
16894
|
-
|
16895
|
-
|
16896
|
-
|
16897
|
-
|
16898
|
-
|
16899
|
-
|
16900
|
-
|
16901
|
-
|
16902
|
-
|
16903
|
-
|
16904
|
-
|
16905
|
-
|
16906
|
-
|
16907
|
-
|
16908
|
-
|
16909
|
-
|
16910
|
-
|
16911
|
-
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
16912
|
-
isAssignable = false;
|
16913
|
-
}
|
16914
|
-
}
|
16916
|
+
if (!isAssignable ||
|
16917
|
+
!(0, types_1.isInstantiableClass)(baseClass) ||
|
16918
|
+
types_1.ClassType.isBuiltIn(baseClass, ['object', 'Protocol', 'Generic']) ||
|
16919
|
+
baseClass.shared.typeParams.length === 0) {
|
16920
|
+
return;
|
16921
|
+
}
|
16922
|
+
const specializedDestBaseClass = (0, typeUtils_1.specializeForBaseClass)(destType, baseClass);
|
16923
|
+
const specializedSrcBaseClass = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
16924
|
+
if (!ignoreBaseClassVariance) {
|
16925
|
+
specializedDestBaseClass.shared.typeParams.forEach((param, index) => {
|
16926
|
+
if ((0, types_1.isParamSpec)(param) || (0, types_1.isTypeVarTuple)(param) || param.shared.isSynthesized) {
|
16927
|
+
return;
|
16928
|
+
}
|
16929
|
+
if (!specializedSrcBaseClass.priv.typeArgs ||
|
16930
|
+
index >= specializedSrcBaseClass.priv.typeArgs.length ||
|
16931
|
+
!specializedDestBaseClass.priv.typeArgs ||
|
16932
|
+
index >= specializedDestBaseClass.priv.typeArgs.length) {
|
16933
|
+
return;
|
16934
|
+
}
|
16935
|
+
const paramVariance = param.shared.declaredVariance;
|
16936
|
+
if ((0, types_1.isTypeVar)(specializedSrcBaseClass.priv.typeArgs[index])) {
|
16937
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 4 /* Variance.Contravariant */) {
|
16938
|
+
isAssignable = false;
|
16939
|
+
return;
|
16915
16940
|
}
|
16916
|
-
}
|
16917
|
-
|
16918
|
-
|
16919
|
-
|
16920
|
-
|
16921
|
-
|
16941
|
+
}
|
16942
|
+
if ((0, types_1.isTypeVar)(specializedDestBaseClass.priv.typeArgs[index])) {
|
16943
|
+
if (paramVariance === 2 /* Variance.Invariant */ || paramVariance === 3 /* Variance.Covariant */) {
|
16944
|
+
isAssignable = false;
|
16945
|
+
return;
|
16946
|
+
}
|
16947
|
+
}
|
16948
|
+
});
|
16949
|
+
}
|
16950
|
+
if (!isAssignable) {
|
16951
|
+
return;
|
16952
|
+
}
|
16953
|
+
// Handle tuples specially since their type arguments are variadic.
|
16954
|
+
if (types_1.ClassType.isTupleClass(specializedDestBaseClass)) {
|
16955
|
+
return;
|
16956
|
+
}
|
16957
|
+
if (!assignClassToSelf(specializedDestBaseClass, specializedSrcBaseClass, assumedVariance, ignoreBaseClassVariance, recursionCount)) {
|
16958
|
+
isAssignable = false;
|
16922
16959
|
}
|
16923
16960
|
});
|
16924
16961
|
return isAssignable;
|