@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
@@ -2242,7 +2242,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2242
2242
  // Limit only to expressions that contain a narrowable subexpression
2243
2243
  // that is a name. This avoids complexities with composite expressions like
2244
2244
  // member access or index expressions.
2245
- if (this._isNarrowingExpression(node, expressionList, /* neverNarrowingExpressions */ true)) {
2245
+ if (this._isNarrowingExpression(node, expressionList, { filterForNeverNarrowing: true })) {
2246
2246
  const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* ParseNodeType.Name */);
2247
2247
  if (filteredExprList.length > 0) {
2248
2248
  this._currentFlowNode = this._createFlowConditional(isPositiveTest ? codeFlowTypes_1.FlowFlags.TrueNeverCondition : codeFlowTypes_1.FlowFlags.FalseNeverCondition, this._currentFlowNode, node);
@@ -2282,10 +2282,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2282
2282
  return Binder._unreachableFlowNode;
2283
2283
  }
2284
2284
  const expressionList = [];
2285
- if (!this._isNarrowingExpression(expression, expressionList,
2286
- /* filterForNeverNarrowing */ (flags &
2287
- (codeFlowTypes_1.FlowFlags.TrueNeverCondition | codeFlowTypes_1.FlowFlags.FalseNeverCondition)) !==
2288
- 0)) {
2285
+ if (!this._isNarrowingExpression(expression, expressionList, {
2286
+ filterForNeverNarrowing: (flags & (codeFlowTypes_1.FlowFlags.TrueNeverCondition | codeFlowTypes_1.FlowFlags.FalseNeverCondition)) !== 0,
2287
+ })) {
2289
2288
  return antecedent;
2290
2289
  }
2291
2290
  expressionList.forEach((expr) => {
@@ -2324,12 +2323,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2324
2323
  // The isComplexExpression parameter is used internally to determine whether
2325
2324
  // the call is an atom (name, member access, index - plus a "not" form of
2326
2325
  // these) or something more complex (binary operator, call, etc.).
2327
- _isNarrowingExpression(expression, expressionList, filterForNeverNarrowing = false, isComplexExpression = false) {
2326
+ _isNarrowingExpression(expression, expressionList, options = {}) {
2328
2327
  switch (expression.nodeType) {
2329
2328
  case 38 /* ParseNodeType.Name */:
2330
2329
  case 35 /* ParseNodeType.MemberAccess */:
2331
2330
  case 27 /* ParseNodeType.Index */: {
2332
- if (filterForNeverNarrowing) {
2331
+ if (options.filterForNeverNarrowing) {
2333
2332
  // Never narrowing doesn't support member access or index
2334
2333
  // expressions.
2335
2334
  if (expression.nodeType !== 38 /* ParseNodeType.Name */) {
@@ -2338,17 +2337,17 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2338
2337
  // Never narrowing doesn't support simple names (falsy
2339
2338
  // or truthy narrowing) because it's too expensive and
2340
2339
  // provides relatively little utility.
2341
- if (!isComplexExpression) {
2340
+ if (!options.isComplexExpression) {
2342
2341
  return false;
2343
2342
  }
2344
2343
  }
2345
2344
  if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression)) {
2346
2345
  expressionList.push(expression);
2347
- if (!filterForNeverNarrowing) {
2346
+ if (!options.filterForNeverNarrowing) {
2348
2347
  // If the expression is a member access expression, add its
2349
2348
  // leftExpression to the expression list because that expression
2350
2349
  // can be narrowed based on the attribute type.
2351
- if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
2350
+ if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */ && options.allowDiscriminatedNarrowing) {
2352
2351
  if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.d.leftExpr)) {
2353
2352
  expressionList.push(expression.d.leftExpr);
2354
2353
  }
@@ -2371,8 +2370,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2371
2370
  }
2372
2371
  case 4 /* ParseNodeType.AssignmentExpression */: {
2373
2372
  expressionList.push(expression.d.name);
2374
- this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
2375
- /* isComplexExpression */ true);
2373
+ this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
2374
+ ...options,
2375
+ isComplexExpression: true,
2376
+ });
2376
2377
  return true;
2377
2378
  }
2378
2379
  case 7 /* ParseNodeType.BinaryOperation */: {
@@ -2383,8 +2384,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2383
2384
  // These are commonly-used patterns used in control flow.
2384
2385
  if (expression.d.rightExpr.nodeType === 14 /* ParseNodeType.Constant */ &&
2385
2386
  expression.d.rightExpr.d.constType === 26 /* KeywordType.None */) {
2386
- return this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
2387
- /* isComplexExpression */ true);
2387
+ return this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
2388
+ ...options,
2389
+ isComplexExpression: true,
2390
+ allowDiscriminatedNarrowing: true,
2391
+ });
2388
2392
  }
2389
2393
  // Look for "type(X) is Y" or "type(X) is not Y".
2390
2394
  if (isOrIsNotOperator &&
@@ -2393,11 +2397,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2393
2397
  expression.d.leftExpr.d.leftExpr.d.value === 'type' &&
2394
2398
  expression.d.leftExpr.d.args.length === 1 &&
2395
2399
  expression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgCategory.Simple */) {
2396
- return this._isNarrowingExpression(expression.d.leftExpr.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
2397
- /* isComplexExpression */ true);
2400
+ return this._isNarrowingExpression(expression.d.leftExpr.d.args[0].d.valueExpr, expressionList, { ...options, isComplexExpression: true });
2398
2401
  }
2399
- const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
2400
- /* isComplexExpression */ true);
2402
+ const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
2403
+ ...options,
2404
+ isComplexExpression: true,
2405
+ allowDiscriminatedNarrowing: true,
2406
+ });
2401
2407
  // Look for "X is Y" or "X is not Y".
2402
2408
  // Look for X == <literal> or X != <literal>
2403
2409
  // Look for len(X) == <literal> or len(X) != <literal>
@@ -2409,61 +2415,79 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2409
2415
  expression.d.operator === 21 /* OperatorType.LessThanOrEqual */ ||
2410
2416
  expression.d.operator === 15 /* OperatorType.GreaterThan */ ||
2411
2417
  expression.d.operator === 16 /* OperatorType.GreaterThanOrEqual */) {
2412
- const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
2413
- /* isComplexExpression */ true);
2418
+ const isLeftNarrowing = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
2419
+ ...options,
2420
+ isComplexExpression: true,
2421
+ });
2414
2422
  return isLeftNarrowing;
2415
2423
  }
2416
2424
  }
2417
2425
  // Look for "<string> in Y" or "<string> not in Y".
2418
2426
  if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
2419
2427
  if (expression.d.leftExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
2420
- this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
2421
- /* isComplexExpression */ true)) {
2428
+ this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
2429
+ ...options,
2430
+ isComplexExpression: true,
2431
+ })) {
2422
2432
  return true;
2423
2433
  }
2424
2434
  }
2425
2435
  // Look for "X in Y" or "X not in Y".
2426
2436
  if (expression.d.operator === 41 /* OperatorType.In */ || expression.d.operator === 42 /* OperatorType.NotIn */) {
2427
- const isLeftNarrowable = this._isNarrowingExpression(expression.d.leftExpr, expressionList, filterForNeverNarrowing,
2428
- /* isComplexExpression */ true);
2429
- const isRightNarrowable = this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
2430
- /* isComplexExpression */ true);
2437
+ const isLeftNarrowable = this._isNarrowingExpression(expression.d.leftExpr, expressionList, {
2438
+ ...options,
2439
+ isComplexExpression: true,
2440
+ });
2441
+ const isRightNarrowable = this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
2442
+ ...options,
2443
+ isComplexExpression: true,
2444
+ });
2431
2445
  return isLeftNarrowable || isRightNarrowable;
2432
2446
  }
2433
2447
  return false;
2434
2448
  }
2435
2449
  case 55 /* ParseNodeType.UnaryOperation */: {
2436
2450
  return (expression.d.operator === 38 /* OperatorType.Not */ &&
2437
- this._isNarrowingExpression(expression.d.expr, expressionList, filterForNeverNarrowing,
2438
- /* isComplexExpression */ false));
2451
+ this._isNarrowingExpression(expression.d.expr, expressionList, {
2452
+ ...options,
2453
+ isComplexExpression: false,
2454
+ }));
2439
2455
  }
2440
2456
  case 5 /* ParseNodeType.AugmentedAssignment */: {
2441
- return this._isNarrowingExpression(expression.d.rightExpr, expressionList, filterForNeverNarrowing,
2442
- /* isComplexExpression */ true);
2457
+ return this._isNarrowingExpression(expression.d.rightExpr, expressionList, {
2458
+ ...options,
2459
+ isComplexExpression: true,
2460
+ });
2443
2461
  }
2444
2462
  case 9 /* ParseNodeType.Call */: {
2445
2463
  if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
2446
2464
  (expression.d.leftExpr.d.value === 'isinstance' ||
2447
2465
  expression.d.leftExpr.d.value === 'issubclass') &&
2448
2466
  expression.d.args.length === 2) {
2449
- return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
2450
- /* isComplexExpression */ true);
2467
+ return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
2468
+ ...options,
2469
+ isComplexExpression: true,
2470
+ });
2451
2471
  }
2452
2472
  if (expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
2453
2473
  expression.d.leftExpr.d.value === 'callable' &&
2454
2474
  expression.d.args.length === 1) {
2455
- return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
2456
- /* isComplexExpression */ true);
2475
+ return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
2476
+ ...options,
2477
+ isComplexExpression: true,
2478
+ });
2457
2479
  }
2458
2480
  // Is this potentially a call to a user-defined type guard function?
2459
2481
  if (expression.d.args.length >= 1) {
2460
2482
  // Never narrowing doesn't support type guards because they do not
2461
2483
  // offer negative narrowing.
2462
- if (filterForNeverNarrowing) {
2484
+ if (options.filterForNeverNarrowing) {
2463
2485
  return false;
2464
2486
  }
2465
- return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, filterForNeverNarrowing,
2466
- /* isComplexExpression */ true);
2487
+ return this._isNarrowingExpression(expression.d.args[0].d.valueExpr, expressionList, {
2488
+ ...options,
2489
+ isComplexExpression: true,
2490
+ });
2467
2491
  }
2468
2492
  }
2469
2493
  }