@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.
Files changed (71) hide show
  1. package/dist/analyzer/binder.js +61 -37
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/constraintSolver.js +11 -1
  4. package/dist/analyzer/constraintSolver.js.map +1 -1
  5. package/dist/analyzer/dataClasses.js +1 -17
  6. package/dist/analyzer/dataClasses.js.map +1 -1
  7. package/dist/analyzer/declarationUtils.js +1 -3
  8. package/dist/analyzer/declarationUtils.js.map +1 -1
  9. package/dist/analyzer/operations.js +2 -2
  10. package/dist/analyzer/operations.js.map +1 -1
  11. package/dist/analyzer/parseTreeUtils.js +4 -0
  12. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  13. package/dist/analyzer/service.js +5 -5
  14. package/dist/analyzer/service.js.map +1 -1
  15. package/dist/analyzer/symbol.d.ts +8 -3
  16. package/dist/analyzer/symbol.js +4 -4
  17. package/dist/analyzer/symbol.js.map +1 -1
  18. package/dist/analyzer/typeEvaluator.js +101 -64
  19. package/dist/analyzer/typeEvaluator.js.map +1 -1
  20. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -5
  21. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  22. package/dist/analyzer/typeGuards.js +3 -5
  23. package/dist/analyzer/typeGuards.js.map +1 -1
  24. package/dist/analyzer/typePrinter.d.ts +1 -1
  25. package/dist/analyzer/typePrinter.js +17 -17
  26. package/dist/analyzer/typePrinter.js.map +1 -1
  27. package/dist/analyzer/typeUtils.d.ts +2 -1
  28. package/dist/analyzer/typeUtils.js +17 -6
  29. package/dist/analyzer/typeUtils.js.map +1 -1
  30. package/dist/analyzer/types.d.ts +1 -1
  31. package/dist/analyzer/types.js +3 -1
  32. package/dist/analyzer/types.js.map +1 -1
  33. package/dist/common/configOptions.d.ts +1 -1
  34. package/dist/common/configOptions.js +4 -3
  35. package/dist/common/configOptions.js.map +1 -1
  36. package/dist/languageService/completionProvider.js +2 -2
  37. package/dist/languageService/completionProvider.js.map +1 -1
  38. package/dist/languageService/definitionProvider.d.ts +2 -0
  39. package/dist/languageService/definitionProvider.js +21 -5
  40. package/dist/languageService/definitionProvider.js.map +1 -1
  41. package/dist/languageService/hoverProvider.js +5 -4
  42. package/dist/languageService/hoverProvider.js.map +1 -1
  43. package/dist/localization/localize.d.ts +4 -0
  44. package/dist/localization/localize.js +10 -1
  45. package/dist/localization/localize.js.map +1 -1
  46. package/dist/localization/package.nls.cs.json +3 -1
  47. package/dist/localization/package.nls.de.json +2 -0
  48. package/dist/localization/package.nls.en-us.json +4 -0
  49. package/dist/localization/package.nls.es.json +2 -0
  50. package/dist/localization/package.nls.fr.json +2 -0
  51. package/dist/localization/package.nls.it.json +3 -1
  52. package/dist/localization/package.nls.ja.json +2 -0
  53. package/dist/localization/package.nls.ko.json +2 -0
  54. package/dist/localization/package.nls.pl.json +2 -0
  55. package/dist/localization/package.nls.pt-br.json +3 -1
  56. package/dist/localization/package.nls.qps-ploc.json +3 -1
  57. package/dist/localization/package.nls.ru.json +3 -1
  58. package/dist/localization/package.nls.tr.json +2 -0
  59. package/dist/localization/package.nls.zh-cn.json +2 -0
  60. package/dist/localization/package.nls.zh-tw.json +3 -1
  61. package/dist/server.d.ts +1 -2
  62. package/dist/tests/fourslash/import.multipart2.fourslash.d.ts +1 -0
  63. package/dist/tests/fourslash/import.multipart2.fourslash.js +20 -0
  64. package/dist/tests/fourslash/import.multipart2.fourslash.js.map +1 -0
  65. package/dist/tests/typeEvaluator2.test.js +4 -0
  66. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  67. package/dist/tests/typeEvaluator3.test.js +4 -0
  68. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  69. package/dist/tests/typeEvaluator4.test.js +3 -3
  70. package/dist/tests/typeEvaluator5.test.js +1 -1
  71. 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.set(param.name, {
7317
- argsNeeded: param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType ? 1 : 0,
7318
- argsReceived: 0,
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
- // Is the declaration in the same execution scope as the "usageNode" node?
15092
- const usageScope = ParseTreeUtils.getExecutionScopeNode(node);
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 declScope = ParseTreeUtils.getExecutionScopeNode(declNode);
15099
- if (usageScope === declScope) {
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 declarations = [];
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)(declarations, symbol.getDeclarations());
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 declarations.length === 0 ? undefined : { decls: declarations, synthesizedTypes: [] };
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 declarations = [];
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)(declarations, (0, declarationUtils_1.getDeclarationsWithUsesLocalNameRemoved)(declsForThisImport));
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)(declarations, typedDecls);
15432
+ (0, collectionUtils_1.appendArray)(decls, typedDecls);
15411
15433
  }
15412
15434
  else {
15413
- const synthesizedType = symbol.getSynthesizedType();
15414
- if (synthesizedType) {
15415
- synthesizedTypes.push({ type: synthesizedType, node });
15416
- }
15417
- else {
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
- declarations.push((0, declarationUtils_1.synthesizeAliasDeclaration)(importInfo.resolvedUris[namePartIndex]));
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
- declarations.push(paramDecl);
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
- declarations.push(paramDecl);
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
- declarations.push(paramDecl);
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)(declarations, lookupResults.symbol.getDeclarations());
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)(declarations, symbolWithScope.symbol.getDeclarations());
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: declarations, synthesizedTypes };
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
- const synthesizedType = symbol.getSynthesizedType();
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 ((0, types_1.isInstantiableClass)(baseClass) &&
16888
- !types_1.ClassType.isBuiltIn(baseClass, 'object') &&
16889
- !types_1.ClassType.isBuiltIn(baseClass, 'Protocol') &&
16890
- !types_1.ClassType.isBuiltIn(baseClass, 'Generic') &&
16891
- baseClass.shared.typeParams.length > 0) {
16892
- const specializedDestBaseClass = (0, typeUtils_1.specializeForBaseClass)(destType, baseClass);
16893
- const specializedSrcBaseClass = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
16894
- if (!ignoreBaseClassVariance) {
16895
- specializedDestBaseClass.shared.typeParams.forEach((param, index) => {
16896
- if (!(0, types_1.isParamSpec)(param) &&
16897
- !(0, types_1.isTypeVarTuple)(param) &&
16898
- !param.shared.isSynthesized &&
16899
- specializedSrcBaseClass.priv.typeArgs &&
16900
- index < specializedSrcBaseClass.priv.typeArgs.length &&
16901
- specializedDestBaseClass.priv.typeArgs &&
16902
- index < specializedDestBaseClass.priv.typeArgs.length) {
16903
- const paramVariance = param.shared.declaredVariance;
16904
- if ((0, types_1.isTypeVar)(specializedSrcBaseClass.priv.typeArgs[index])) {
16905
- if (paramVariance === 2 /* Variance.Invariant */ ||
16906
- paramVariance === 4 /* Variance.Contravariant */) {
16907
- isAssignable = false;
16908
- }
16909
- }
16910
- else if ((0, types_1.isTypeVar)(specializedDestBaseClass.priv.typeArgs[index])) {
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
- if (isAssignable &&
16919
- !assignClassToSelf(specializedDestBaseClass, specializedSrcBaseClass, assumedVariance, ignoreBaseClassVariance, recursionCount)) {
16920
- isAssignable = false;
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;