@zzzen/pyright-internal 1.2.0-dev.20260809 → 1.2.0-dev.20260816

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 (53) hide show
  1. package/dist/analyzer/binder.js +87 -1
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +1 -0
  4. package/dist/analyzer/checker.js +37 -0
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/constraintSolver.js +47 -7
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/constructors.js +18 -8
  9. package/dist/analyzer/constructors.js.map +1 -1
  10. package/dist/analyzer/dataClasses.d.ts +1 -0
  11. package/dist/analyzer/dataClasses.js +98 -19
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/decorators.js +18 -0
  14. package/dist/analyzer/decorators.js.map +1 -1
  15. package/dist/analyzer/scope.d.ts +3 -0
  16. package/dist/analyzer/scope.js +10 -0
  17. package/dist/analyzer/scope.js.map +1 -1
  18. package/dist/analyzer/symbol.d.ts +4 -1
  19. package/dist/analyzer/symbol.js +8 -0
  20. package/dist/analyzer/symbol.js.map +1 -1
  21. package/dist/analyzer/typeCacheUtils.d.ts +6 -2
  22. package/dist/analyzer/typeCacheUtils.js +16 -37
  23. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  24. package/dist/analyzer/typeEvaluator.js +955 -105
  25. package/dist/analyzer/typeEvaluator.js.map +1 -1
  26. package/dist/analyzer/typeGuards.js +11 -8
  27. package/dist/analyzer/typeGuards.js.map +1 -1
  28. package/dist/analyzer/types.d.ts +11 -1
  29. package/dist/analyzer/types.js +48 -0
  30. package/dist/analyzer/types.js.map +1 -1
  31. package/dist/localization/localize.d.ts +6 -0
  32. package/dist/localization/localize.js +4 -0
  33. package/dist/localization/localize.js.map +1 -1
  34. package/dist/localization/package.nls.en-us.json +13 -0
  35. package/dist/tests/typeCacheUtils.test.d.ts +1 -0
  36. package/dist/tests/typeCacheUtils.test.js +69 -0
  37. package/dist/tests/typeCacheUtils.test.js.map +1 -0
  38. package/dist/tests/typeEvaluator3.test.js +8 -0
  39. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  40. package/dist/tests/typeEvaluator5.test.js +12 -0
  41. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  42. package/dist/tests/typeEvaluator6.test.js +33 -1
  43. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  44. package/dist/tests/typeEvaluator7.test.js +25 -0
  45. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  46. package/dist/tests/typeEvaluator8.test.js +318 -4
  47. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  48. package/dist/tests/types.test.d.ts +1 -0
  49. package/dist/tests/types.test.js +63 -0
  50. package/dist/tests/types.test.js.map +1 -0
  51. package/dist/typeServer/typeGuards.js +4 -3
  52. package/dist/typeServer/typeGuards.js.map +1 -1
  53. package/package.json +1 -1
@@ -68,6 +68,63 @@ const scope_1 = require("./scope");
68
68
  const StaticExpressions = __importStar(require("./staticExpressions"));
69
69
  const symbol_1 = require("./symbol");
70
70
  const symbolNameUtils_1 = require("./symbolNameUtils");
71
+ function isStaticClassAssignmentTarget(target) {
72
+ switch (target.nodeType) {
73
+ case 38 /* ParseNodeType.Name */:
74
+ return true;
75
+ case 54 /* ParseNodeType.TypeAnnotation */:
76
+ return isStaticClassAssignmentTarget(target.d.valueExpr);
77
+ case 52 /* ParseNodeType.Tuple */:
78
+ case 34 /* ParseNodeType.List */:
79
+ return target.d.items.every((item) => isStaticClassAssignmentTarget(item));
80
+ case 56 /* ParseNodeType.Unpack */:
81
+ return isStaticClassAssignmentTarget(target.d.expr);
82
+ default:
83
+ return false;
84
+ }
85
+ }
86
+ function getCalledBuiltInName(scope, expression, visitedSymbols = new Set()) {
87
+ if (expression.nodeType === 38 /* ParseNodeType.Name */) {
88
+ const symbolWithScope = scope.lookUpSymbolRecursive(expression.d.value);
89
+ if (!symbolWithScope || visitedSymbols.has(symbolWithScope.symbol)) {
90
+ return undefined;
91
+ }
92
+ visitedSymbols.add(symbolWithScope.symbol);
93
+ if (symbolWithScope.scope.type === 5 /* ScopeType.Builtin */) {
94
+ return expression.d.value;
95
+ }
96
+ const declarations = symbolWithScope.symbol.getDeclarations();
97
+ const declaration = declarations[declarations.length - 1];
98
+ if (declaration?.type === 1 /* DeclarationType.Variable */ &&
99
+ (declaration.inferredTypeSource?.nodeType === 38 /* ParseNodeType.Name */ ||
100
+ declaration.inferredTypeSource?.nodeType === 35 /* ParseNodeType.MemberAccess */)) {
101
+ return getCalledBuiltInName(scope, declaration.inferredTypeSource, visitedSymbols);
102
+ }
103
+ if (declaration?.type === 8 /* DeclarationType.Alias */ &&
104
+ declaration.moduleName === 'builtins' &&
105
+ declaration.symbolName) {
106
+ return declaration.symbolName;
107
+ }
108
+ }
109
+ else if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
110
+ expression.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */) {
111
+ const symbolWithScope = scope.lookUpSymbolRecursive(expression.d.leftExpr.d.value);
112
+ const declarations = symbolWithScope?.symbol.getDeclarations() ?? [];
113
+ const declaration = declarations[declarations.length - 1];
114
+ if (declaration?.type === 8 /* DeclarationType.Alias */ &&
115
+ declaration.moduleName === 'builtins' &&
116
+ !declaration.symbolName) {
117
+ return expression.d.member.d.value;
118
+ }
119
+ }
120
+ return undefined;
121
+ }
122
+ function doesCallExposeClassNamespace(scope, node) {
123
+ const builtInName = getCalledBuiltInName(scope, node.d.leftExpr);
124
+ return (builtInName === 'exec' ||
125
+ (builtInName === 'eval' && node.d.args.length === 1) ||
126
+ ((builtInName === 'locals' || builtInName === 'vars') && node.d.args.length === 0));
127
+ }
71
128
  // For each flow node within an execution context, we'll add a small
72
129
  // amount to the complexity factor. Without this, the complexity
73
130
  // calculation fails to take into account large numbers of non-cyclical
@@ -480,6 +537,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
480
537
  return false;
481
538
  }
482
539
  visitCall(node) {
540
+ if (this._currentScope.type === 3 /* ScopeType.Class */ && doesCallExposeClassNamespace(this._currentScope, node)) {
541
+ this._currentScope.hasPotentiallyDynamicSymbolTable = true;
542
+ }
483
543
  this._disableTrueFalseTargets(() => {
484
544
  this.walk(node.d.leftExpr);
485
545
  const sortedArgs = ParseTreeUtils.getArgsByRuntimeOrder(node);
@@ -766,9 +826,23 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
766
826
  }
767
827
  });
768
828
  }
829
+ else if (expr.nodeType === 18 /* ParseNodeType.Dictionary */) {
830
+ expr.d.items.forEach((dictionaryEntryNode) => {
831
+ if (dictionaryEntryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */ &&
832
+ dictionaryEntryNode.d.keyExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
833
+ dictionaryEntryNode.d.keyExpr.d.strings.length === 1 &&
834
+ dictionaryEntryNode.d.keyExpr.d.strings[0].nodeType === 49 /* ParseNodeType.String */) {
835
+ this._dunderSlotsEntries.push(dictionaryEntryNode.d.keyExpr);
836
+ }
837
+ else {
838
+ isExpressionUnderstood = false;
839
+ }
840
+ });
841
+ }
769
842
  else {
770
843
  isExpressionUnderstood = false;
771
844
  }
845
+ this._currentScope.setHasNonEmptySlots(this._dunderSlotsEntries.some((entry) => entry.d.strings[0].d.value !== '__dict__'));
772
846
  if (!isExpressionUnderstood) {
773
847
  this._dunderSlotsEntries = undefined;
774
848
  }
@@ -1414,7 +1488,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1414
1488
  }
1415
1489
  visitImportFrom(node) {
1416
1490
  const typingSymbolsOfInterest = ['Final', 'ClassVar', 'Annotated'];
1417
- const dataclassesSymbolsOfInterest = ['InitVar'];
1491
+ const dataclassesSymbolsOfInterest = ['InitVar', 'KW_ONLY'];
1418
1492
  const importInfo = AnalyzerNodeInfo.getImportInfo(node.d.module);
1419
1493
  AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
1420
1494
  let resolvedPath = uri_1.Uri.empty();
@@ -2893,6 +2967,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2893
2967
  return undefined;
2894
2968
  }
2895
2969
  _bindPossibleTupleNamedTarget(target, addedSymbols) {
2970
+ if (this._currentScope.type === 3 /* ScopeType.Class */ && !isStaticClassAssignmentTarget(target)) {
2971
+ this._currentScope.hasPotentiallyDynamicSymbolTable = true;
2972
+ }
2896
2973
  switch (target.nodeType) {
2897
2974
  case 38 /* ParseNodeType.Name */: {
2898
2975
  this._bindNameToScope(this._currentScope, target, addedSymbols);
@@ -3183,6 +3260,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3183
3260
  }
3184
3261
  }
3185
3262
  }
3263
+ if (this._isDataclassesAnnotation(typeAnnotation, 'KW_ONLY')) {
3264
+ symbolWithScope.symbol.setIsDataClassKeywordOnly();
3265
+ }
3266
+ else if (typeAnnotation.nodeType === 27 /* ParseNodeType.Index */ &&
3267
+ this._isTypingAnnotation(typeAnnotation.d.leftExpr, 'Annotated') &&
3268
+ typeAnnotation.d.items.length > 0 &&
3269
+ this._isDataclassesAnnotation(typeAnnotation.d.items[0].d.valueExpr, 'KW_ONLY')) {
3270
+ symbolWithScope.symbol.setIsDataClassKeywordOnly();
3271
+ }
3186
3272
  }
3187
3273
  declarationHandled = true;
3188
3274
  break;