@zzzen/pyright-internal 1.2.0-dev.20220814 → 1.2.0-dev.20220904

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 (54) hide show
  1. package/dist/analyzer/binder.js +28 -27
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +15 -1
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/patternMatching.js +10 -0
  6. package/dist/analyzer/patternMatching.js.map +1 -1
  7. package/dist/analyzer/program.d.ts +1 -0
  8. package/dist/analyzer/program.js +8 -1
  9. package/dist/analyzer/program.js.map +1 -1
  10. package/dist/analyzer/service.d.ts +1 -1
  11. package/dist/analyzer/service.js +3 -1
  12. package/dist/analyzer/service.js.map +1 -1
  13. package/dist/analyzer/sourceFile.d.ts +2 -1
  14. package/dist/analyzer/sourceFile.js +4 -3
  15. package/dist/analyzer/sourceFile.js.map +1 -1
  16. package/dist/analyzer/typeEvaluator.js +136 -83
  17. package/dist/analyzer/typeEvaluator.js.map +1 -1
  18. package/dist/analyzer/typeGuards.js +44 -14
  19. package/dist/analyzer/typeGuards.js.map +1 -1
  20. package/dist/analyzer/typeUtils.d.ts +1 -1
  21. package/dist/analyzer/typeUtils.js +2 -2
  22. package/dist/analyzer/typeUtils.js.map +1 -1
  23. package/dist/analyzer/typedDicts.d.ts +3 -3
  24. package/dist/analyzer/typedDicts.js +9 -5
  25. package/dist/analyzer/typedDicts.js.map +1 -1
  26. package/dist/analyzer/types.js +8 -7
  27. package/dist/analyzer/types.js.map +1 -1
  28. package/dist/common/diagnostic.d.ts +5 -1
  29. package/dist/common/diagnostic.js +34 -0
  30. package/dist/common/diagnostic.js.map +1 -1
  31. package/dist/languageServerBase.d.ts +1 -1
  32. package/dist/languageServerBase.js +22 -17
  33. package/dist/languageServerBase.js.map +1 -1
  34. package/dist/localization/localize.d.ts +1 -0
  35. package/dist/localization/localize.js +1 -0
  36. package/dist/localization/localize.js.map +1 -1
  37. package/dist/localization/package.nls.en-us.json +2 -1
  38. package/dist/parser/parser.js +16 -6
  39. package/dist/parser/parser.js.map +1 -1
  40. package/dist/tests/checker.test.js +2 -2
  41. package/dist/tests/harness/fourslash/testState.d.ts +8 -2
  42. package/dist/tests/harness/fourslash/testState.js +46 -40
  43. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  44. package/dist/tests/ipythonMode.test.js +91 -0
  45. package/dist/tests/ipythonMode.test.js.map +1 -1
  46. package/dist/tests/typeEvaluator1.test.js +5 -1
  47. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  48. package/dist/tests/typeEvaluator2.test.js +5 -1
  49. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  50. package/dist/tests/typeEvaluator3.test.js +6 -0
  51. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  52. package/dist/tests/typeEvaluator4.test.js +6 -2
  53. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  54. package/package.json +1 -1
@@ -45,7 +45,6 @@ const positionUtils_1 = require("../common/positionUtils");
45
45
  const textRange_1 = require("../common/textRange");
46
46
  const textRange_2 = require("../common/textRange");
47
47
  const localize_1 = require("../localization/localize");
48
- const analyzerFileInfo_1 = require("./analyzerFileInfo");
49
48
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
50
49
  const codeFlowTypes_1 = require("./codeFlowTypes");
51
50
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
@@ -539,17 +538,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
539
538
  this.walk(node.typeAnnotationComment);
540
539
  this._addTypeDeclarationForVariable(node.leftExpression, node.typeAnnotationComment);
541
540
  }
542
- // If there is a type annotation associated with the assignment and annotation evaluations are
543
- // not deferred, the Python interpreter creates an entry in the local symbol table (presumably
544
- // to store the __annotation__ attribute) before it evaluates the RHS of the assignment. This
545
- // can affect the evaluation of the RHS if the name of the symbol is the same as a name that
546
- // is defined in an outer scope.
547
- let createdAssignmentTargetFlowNodes = false;
548
- if (node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
549
- !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(this._fileInfo)) {
550
- this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
551
- createdAssignmentTargetFlowNodes = true;
552
- }
553
541
  // If the assignment target base expression is potentially a
554
542
  // TypedDict, add the base expression to the flow expressions set
555
543
  // to accommodate TypedDict type narrowing.
@@ -583,9 +571,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
583
571
  }
584
572
  this._addInferredTypeAssignmentForVariable(node.leftExpression, node.rightExpression, isPossibleTypeAlias);
585
573
  // If we didn't create assignment target flow nodes above, do so now.
586
- if (!createdAssignmentTargetFlowNodes) {
587
- this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
588
- }
574
+ this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
589
575
  // Is this an assignment to dunder all?
590
576
  if (this._currentScope.type === 3 /* Module */) {
591
577
  if ((node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === '__all__') ||
@@ -770,9 +756,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
770
756
  if (this._handleTypingStubAssignmentOrAnnotation(node)) {
771
757
  return false;
772
758
  }
773
- // Walk the type annotation first so it is "before" the target
774
- // in the code flow graph.
775
- this.walk(node.typeAnnotation);
759
+ // We normally want to walk the type annotation first so it is "before"
760
+ // the target in the code flow graph, but this is reversed for class variables
761
+ // declared within a class body.
762
+ const evaluateAnnotationAfterAssignment = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
763
+ if (!evaluateAnnotationAfterAssignment) {
764
+ this.walk(node.typeAnnotation);
765
+ }
776
766
  this._createVariableAnnotationFlowNode();
777
767
  this._bindPossibleTupleNamedTarget(node.valueExpression);
778
768
  this._addTypeDeclarationForVariable(node.valueExpression, node.typeAnnotation);
@@ -788,6 +778,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
788
778
  });
789
779
  }
790
780
  this.walk(node.valueExpression);
781
+ if (evaluateAnnotationAfterAssignment) {
782
+ this.walk(node.typeAnnotation);
783
+ }
791
784
  return false;
792
785
  }
793
786
  visitFor(node) {
@@ -818,7 +811,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
818
811
  }
819
812
  this._addAntecedent(postForLabel, this._currentFlowNode);
820
813
  this._currentFlowNode = this._finishFlowLabel(postForLabel);
821
- if (node.asyncToken) {
814
+ // Async for is not allowed outside of an async function
815
+ // unless we're in ipython mode.
816
+ if (node.asyncToken && !this._fileInfo.ipythonMode) {
822
817
  const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
823
818
  if (!enclosingFunction || !enclosingFunction.isAsync) {
824
819
  this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
@@ -1504,7 +1499,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1504
1499
  if (!this._isCodeUnreachable()) {
1505
1500
  this._addExceptTargets(this._currentFlowNode);
1506
1501
  }
1507
- if (node.asyncToken) {
1502
+ if (node.asyncToken && !this._fileInfo.ipythonMode) {
1503
+ // Top level async with is allowed in ipython mode.
1508
1504
  const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1509
1505
  if (!enclosingFunction || !enclosingFunction.isAsync) {
1510
1506
  this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
@@ -1597,8 +1593,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1597
1593
  if (compr.nodeType === 33 /* ListComprehensionFor */) {
1598
1594
  this._bindPossibleTupleNamedTarget(compr.targetExpression, addedSymbols);
1599
1595
  this._addInferredTypeAssignmentForVariable(compr.targetExpression, compr);
1600
- // Async for is not allowed outside of an async function.
1601
- if (compr.asyncToken) {
1596
+ // Async for is not allowed outside of an async function
1597
+ // unless we're in ipython mode.
1598
+ if (compr.asyncToken && !this._fileInfo.ipythonMode) {
1602
1599
  if (!enclosingFunction || !enclosingFunction.isAsync) {
1603
1600
  // Allow if it's within a generator expression. Execution of
1604
1601
  // generator expressions is deferred and therefore can be
@@ -1833,7 +1830,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1833
1830
  // Attempts to resolve the module name, import it, and return
1834
1831
  // its __all__ symbols.
1835
1832
  _getDunderAllNamesFromImport(varName) {
1836
- var _a;
1833
+ var _a, _b;
1837
1834
  const varSymbol = this._currentScope.lookUpSymbol(varName);
1838
1835
  if (!varSymbol) {
1839
1836
  return undefined;
@@ -1848,11 +1845,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1848
1845
  if (!resolvedPath) {
1849
1846
  return undefined;
1850
1847
  }
1851
- const lookupInfo = this._fileInfo.importLookup(resolvedPath);
1852
- if (!lookupInfo) {
1853
- return undefined;
1848
+ let lookupInfo = this._fileInfo.importLookup(resolvedPath);
1849
+ if (lookupInfo === null || lookupInfo === void 0 ? void 0 : lookupInfo.dunderAllNames) {
1850
+ return lookupInfo.dunderAllNames;
1854
1851
  }
1855
- return lookupInfo.dunderAllNames;
1852
+ if ((_b = aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.submoduleFallback) === null || _b === void 0 ? void 0 : _b.path) {
1853
+ lookupInfo = this._fileInfo.importLookup(aliasDecl.submoduleFallback.path);
1854
+ return lookupInfo === null || lookupInfo === void 0 ? void 0 : lookupInfo.dunderAllNames;
1855
+ }
1856
+ return undefined;
1856
1857
  }
1857
1858
  _addImplicitFromImport(node, importInfo) {
1858
1859
  const symbolName = node.module.nameParts[0].value;