@zzzen/pyright-internal 1.2.0-dev.20261108 → 1.2.0-dev.20261115

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 (74) hide show
  1. package/dist/analyzer/binder.d.ts +1 -0
  2. package/dist/analyzer/binder.js +200 -1
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/codeFlowEngine.js +28 -3
  5. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  6. package/dist/analyzer/constructors.d.ts +1 -1
  7. package/dist/analyzer/constructors.js +68 -9
  8. package/dist/analyzer/constructors.js.map +1 -1
  9. package/dist/analyzer/enums.d.ts +10 -3
  10. package/dist/analyzer/enums.js +389 -2
  11. package/dist/analyzer/enums.js.map +1 -1
  12. package/dist/analyzer/operations.js +81 -4
  13. package/dist/analyzer/operations.js.map +1 -1
  14. package/dist/analyzer/protocols.d.ts +1 -0
  15. package/dist/analyzer/protocols.js +171 -10
  16. package/dist/analyzer/protocols.js.map +1 -1
  17. package/dist/analyzer/scope.d.ts +3 -0
  18. package/dist/analyzer/scope.js +28 -6
  19. package/dist/analyzer/scope.js.map +1 -1
  20. package/dist/analyzer/symbol.d.ts +4 -1
  21. package/dist/analyzer/symbol.js +8 -0
  22. package/dist/analyzer/symbol.js.map +1 -1
  23. package/dist/analyzer/typeEvaluator/evaluatorCore.js +6 -0
  24. package/dist/analyzer/typeEvaluator/evaluatorCore.js.map +1 -1
  25. package/dist/analyzer/typeEvaluator/internals.d.ts +1 -0
  26. package/dist/analyzer/typeEvaluator/typeCompatibility.js +14 -1
  27. package/dist/analyzer/typeEvaluator/typeCompatibility.js.map +1 -1
  28. package/dist/analyzer/typeEvaluator/typeGuardNarrowing.d.ts +2 -1
  29. package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js +87 -7
  30. package/dist/analyzer/typeEvaluator/typeGuardNarrowing.js.map +1 -1
  31. package/dist/analyzer/typeEvaluator.js +87 -6
  32. package/dist/analyzer/typeEvaluator.js.map +1 -1
  33. package/dist/analyzer/typeGuards.js +3 -3
  34. package/dist/analyzer/typeGuards.js.map +1 -1
  35. package/dist/analyzer/typedDicts.js +15 -2
  36. package/dist/analyzer/typedDicts.js.map +1 -1
  37. package/dist/analyzer/types.d.ts +6 -1
  38. package/dist/analyzer/types.js +32 -4
  39. package/dist/analyzer/types.js.map +1 -1
  40. package/dist/common/processUtils.d.ts +1 -0
  41. package/dist/common/processUtils.js +38 -0
  42. package/dist/common/processUtils.js.map +1 -1
  43. package/dist/common/windowsProcessTree.json +20 -2
  44. package/dist/localization/package.nls.cs.json +2 -0
  45. package/dist/localization/package.nls.de.json +2 -0
  46. package/dist/localization/package.nls.es.json +2 -0
  47. package/dist/localization/package.nls.fr.json +2 -0
  48. package/dist/localization/package.nls.it.json +2 -0
  49. package/dist/localization/package.nls.ja.json +2 -0
  50. package/dist/localization/package.nls.ko.json +2 -0
  51. package/dist/localization/package.nls.pl.json +2 -0
  52. package/dist/localization/package.nls.pt-br.json +2 -0
  53. package/dist/localization/package.nls.qps-ploc.json +2 -0
  54. package/dist/localization/package.nls.ru.json +2 -0
  55. package/dist/localization/package.nls.tr.json +2 -0
  56. package/dist/localization/package.nls.zh-cn.json +2 -0
  57. package/dist/localization/package.nls.zh-tw.json +2 -0
  58. package/dist/tests/signatureHelp.test.js +22 -0
  59. package/dist/tests/signatureHelp.test.js.map +1 -1
  60. package/dist/tests/typeEvaluator1.test.js +33 -0
  61. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  62. package/dist/tests/typeEvaluator2.test.js +14 -0
  63. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  64. package/dist/tests/typeEvaluator3.test.js +16 -0
  65. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  66. package/dist/tests/typeEvaluator5.test.js +7 -1
  67. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  68. package/dist/tests/typeEvaluator6.test.js +4 -0
  69. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  70. package/dist/tests/typeEvaluator7.test.js +222 -17
  71. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  72. package/dist/tests/typeEvaluator8.test.js +46 -0
  73. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  74. package/package.json +1 -1
@@ -96,6 +96,7 @@ export declare class Binder extends ParseTreeWalker {
96
96
  private _addImplicitFromImport;
97
97
  private _createAliasDeclarationForMultipartImportName;
98
98
  private _walkStatementsAndReportUnreachable;
99
+ private _bindNamesInUnreachableCode;
99
100
  private _createStartFlowNode;
100
101
  private _createBranchLabel;
101
102
  private _createFlowNarrowForPattern;
@@ -2368,11 +2368,35 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2368
2368
  if (!this._moduleSymbolOnly) {
2369
2369
  const dummyScopeGenerator = new DummyScopeGenerator(this._currentScope, this._nodeInfo);
2370
2370
  dummyScopeGenerator.walk(statement);
2371
+ // Assignments in unreachable code still make names local, matching
2372
+ // CPython. Bind those names without type-checking the dead code.
2373
+ if (this._currentScope.type === 2 /* ScopeType.Function */ || this._currentScope.type === 3 /* ScopeType.Class */) {
2374
+ this._bindNamesInUnreachableCode(statement);
2375
+ }
2371
2376
  }
2372
2377
  }
2373
2378
  }
2374
2379
  return false;
2375
2380
  }
2381
+ _bindNamesInUnreachableCode(node) {
2382
+ // Directives apply to the entire scope, so process global and
2383
+ // nonlocal declarations before binding any names.
2384
+ new UnreachableDirectiveFinder((globalNode) => this.visitGlobal(globalNode), (nonlocalNode) => {
2385
+ if (this._currentScope.type === 3 /* ScopeType.Class */) {
2386
+ nonlocalNode.d.targets.forEach((name) => this._currentScope.excludeUnreachableSymbol(name.d.value));
2387
+ }
2388
+ else {
2389
+ this.visitNonlocal(nonlocalNode);
2390
+ }
2391
+ }).walk(node);
2392
+ const bindTarget = (target) => {
2393
+ this._bindPossibleTupleNamedTarget(target);
2394
+ };
2395
+ const bindName = (name) => {
2396
+ this._bindNameToScope(this._currentScope, name);
2397
+ };
2398
+ new UnreachableNameBinder(bindTarget, bindName).walk(node);
2399
+ }
2376
2400
  _createStartFlowNode() {
2377
2401
  const flowNode = {
2378
2402
  flags: codeFlowTypes_1.FlowFlags.Start,
@@ -2830,6 +2854,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2830
2854
  const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.d.value);
2831
2855
  (0, debug_1.assert)(symbolWithScope !== undefined);
2832
2856
  targetSymbolId = symbolWithScope.symbol.id;
2857
+ if (unbound && !this._isCodeUnreachable() && symbolWithScope.isBeyondExecutionScope) {
2858
+ symbolWithScope.symbol.setIsUnboundInOtherScope();
2859
+ }
2833
2860
  }
2834
2861
  const prevFlowNode = this._currentFlowNode;
2835
2862
  // Record mutations even when the target cannot be narrowed, so presence
@@ -2962,6 +2989,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2962
2989
  }
2963
2990
  }
2964
2991
  else {
2992
+ if (scope.type === 3 /* ScopeType.Class */ && this._isCodeUnreachable()) {
2993
+ return scope.addUnreachableSymbol(name);
2994
+ }
2965
2995
  // Don't overwrite an existing symbol.
2966
2996
  let symbol = scope.lookUpSymbol(name);
2967
2997
  if (!symbol) {
@@ -2997,7 +3027,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2997
3027
  return undefined;
2998
3028
  }
2999
3029
  _bindPossibleTupleNamedTarget(target, addedSymbols) {
3000
- if (this._currentScope.type === 3 /* ScopeType.Class */ && !isStaticClassAssignmentTarget(target)) {
3030
+ if (this._currentScope.type === 3 /* ScopeType.Class */ &&
3031
+ !this._isCodeUnreachable() &&
3032
+ !isStaticClassAssignmentTarget(target)) {
3001
3033
  this._currentScope.hasPotentiallyDynamicSymbolTable = true;
3002
3034
  }
3003
3035
  switch (target.nodeType) {
@@ -3868,6 +3900,173 @@ class ReturnFinder extends parseTreeWalker_1.ParseTreeWalker {
3868
3900
  }
3869
3901
  }
3870
3902
  exports.ReturnFinder = ReturnFinder;
3903
+ // Discovers and processes `global` and `nonlocal` directives in unreachable code.
3904
+ // Directives must be evaluated before binding names to ensure that later
3905
+ // assignments do not bind as locals in the current scope. Nested function,
3906
+ // class, and lambda bodies are skipped because their directives belong to
3907
+ // nested scopes.
3908
+ class UnreachableDirectiveFinder extends parseTreeWalker_1.ParseTreeWalker {
3909
+ constructor(_bindGlobal, _bindNonlocal) {
3910
+ super();
3911
+ this._bindGlobal = _bindGlobal;
3912
+ this._bindNonlocal = _bindNonlocal;
3913
+ }
3914
+ visitGlobal(node) {
3915
+ this._bindGlobal(node);
3916
+ return false;
3917
+ }
3918
+ visitNonlocal(node) {
3919
+ this._bindNonlocal(node);
3920
+ return false;
3921
+ }
3922
+ visitFunction(node) {
3923
+ return false;
3924
+ }
3925
+ visitClass(node) {
3926
+ return false;
3927
+ }
3928
+ visitLambda(node) {
3929
+ return false;
3930
+ }
3931
+ }
3932
+ // Binds assignment targets in unreachable code so they still create local
3933
+ // symbols, matching CPython (an assignment after `return` makes the name
3934
+ // local for the entire function).
3935
+ // Header expressions for nested functions, classes, and lambdas (decorators,
3936
+ // parameter defaults/annotations, type parameters, and class bases/arguments)
3937
+ // are evaluated in the enclosing scope, so they are walked to catch assignment
3938
+ // expressions (:=). Nested bodies are skipped because DummyScopeGenerator
3939
+ // already created their scopes and they belong to nested scopes.
3940
+ class UnreachableNameBinder extends parseTreeWalker_1.ParseTreeWalker {
3941
+ constructor(_bindTarget, _bindName) {
3942
+ super();
3943
+ this._bindTarget = _bindTarget;
3944
+ this._bindName = _bindName;
3945
+ }
3946
+ visitAssignment(node) {
3947
+ this._bindTarget(node.d.leftExpr);
3948
+ return true;
3949
+ }
3950
+ visitAugmentedAssignment(node) {
3951
+ this._bindTarget(node.d.leftExpr);
3952
+ return true;
3953
+ }
3954
+ visitTypeAnnotation(node) {
3955
+ this._bindTarget(node.d.valueExpr);
3956
+ return true;
3957
+ }
3958
+ visitAssignmentExpression(node) {
3959
+ this._bindName(node.d.name);
3960
+ return true;
3961
+ }
3962
+ visitFor(node) {
3963
+ this._bindTarget(node.d.targetExpr);
3964
+ return true;
3965
+ }
3966
+ visitWith(node) {
3967
+ node.d.withItems.forEach((item) => {
3968
+ if (item.d.target) {
3969
+ this._bindTarget(item.d.target);
3970
+ }
3971
+ });
3972
+ return true;
3973
+ }
3974
+ visitDel(node) {
3975
+ node.d.targets.forEach((target) => {
3976
+ this._bindTarget(target);
3977
+ });
3978
+ return true;
3979
+ }
3980
+ visitExcept(node) {
3981
+ if (node.d.name) {
3982
+ this._bindName(node.d.name);
3983
+ }
3984
+ return true;
3985
+ }
3986
+ visitImportAs(node) {
3987
+ if (node.d.alias) {
3988
+ this._bindName(node.d.alias);
3989
+ }
3990
+ else if (node.d.module.d.nameParts.length > 0) {
3991
+ this._bindName(node.d.module.d.nameParts[0]);
3992
+ }
3993
+ return false;
3994
+ }
3995
+ visitImportFrom(node) {
3996
+ node.d.imports.forEach((importSymbolNode) => {
3997
+ this._bindName(importSymbolNode.d.alias || importSymbolNode.d.name);
3998
+ });
3999
+ return false;
4000
+ }
4001
+ visitFunction(node) {
4002
+ this._bindName(node.d.name);
4003
+ this.walkMultiple(node.d.decorators);
4004
+ node.d.params.forEach((param) => {
4005
+ if (param.d.defaultValue) {
4006
+ this.walk(param.d.defaultValue);
4007
+ }
4008
+ if (param.d.annotation) {
4009
+ this.walk(param.d.annotation);
4010
+ }
4011
+ if (param.d.annotationComment) {
4012
+ this.walk(param.d.annotationComment);
4013
+ }
4014
+ });
4015
+ if (node.d.typeParams) {
4016
+ this.walk(node.d.typeParams);
4017
+ }
4018
+ if (node.d.returnAnnotation) {
4019
+ this.walk(node.d.returnAnnotation);
4020
+ }
4021
+ if (node.d.funcAnnotationComment) {
4022
+ this.walk(node.d.funcAnnotationComment);
4023
+ }
4024
+ return false;
4025
+ }
4026
+ visitClass(node) {
4027
+ this._bindName(node.d.name);
4028
+ this.walkMultiple(node.d.decorators);
4029
+ if (node.d.typeParams) {
4030
+ this.walk(node.d.typeParams);
4031
+ }
4032
+ this.walkMultiple(node.d.arguments);
4033
+ return false;
4034
+ }
4035
+ visitLambda(node) {
4036
+ node.d.params.forEach((param) => {
4037
+ if (param.d.defaultValue) {
4038
+ this.walk(param.d.defaultValue);
4039
+ }
4040
+ });
4041
+ return false;
4042
+ }
4043
+ visitTypeAlias(node) {
4044
+ this._bindName(node.d.name);
4045
+ if (node.d.typeParams) {
4046
+ this.walk(node.d.typeParams);
4047
+ }
4048
+ this.walk(node.d.expr);
4049
+ return false;
4050
+ }
4051
+ visitPatternAs(node) {
4052
+ if (node.d.target) {
4053
+ this._bindName(node.d.target);
4054
+ }
4055
+ return true;
4056
+ }
4057
+ visitPatternCapture(node) {
4058
+ if (!node.d.isWildcard) {
4059
+ this._bindName(node.d.target);
4060
+ }
4061
+ return false;
4062
+ }
4063
+ visitPatternMappingExpandEntry(node) {
4064
+ if (node.d.target.d.value !== '_') {
4065
+ this._bindName(node.d.target);
4066
+ }
4067
+ return false;
4068
+ }
4069
+ }
3871
4070
  // Creates dummy scopes for classes or functions within a parse tree.
3872
4071
  // This is needed in cases where the parse tree has been determined
3873
4072
  // to be unreachable. There are code paths where the type evaluator