@zzzen/pyright-internal 1.2.0-dev.20240623 → 1.2.0-dev.20240630

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 (73) hide show
  1. package/dist/analyzer/checker.js +81 -71
  2. package/dist/analyzer/checker.js.map +1 -1
  3. package/dist/analyzer/constructors.js +28 -3
  4. package/dist/analyzer/constructors.js.map +1 -1
  5. package/dist/analyzer/importResolver.d.ts +4 -8
  6. package/dist/analyzer/importResolver.js +87 -85
  7. package/dist/analyzer/importResolver.js.map +1 -1
  8. package/dist/analyzer/patternMatching.js +11 -3
  9. package/dist/analyzer/patternMatching.js.map +1 -1
  10. package/dist/analyzer/service.js +1 -1
  11. package/dist/analyzer/service.js.map +1 -1
  12. package/dist/analyzer/typeEvaluator.js +112 -91
  13. package/dist/analyzer/typeEvaluator.js.map +1 -1
  14. package/dist/analyzer/typeGuards.js +42 -14
  15. package/dist/analyzer/typeGuards.js.map +1 -1
  16. package/dist/analyzer/typeUtils.js +16 -8
  17. package/dist/analyzer/typeUtils.js.map +1 -1
  18. package/dist/analyzer/types.js +2 -1
  19. package/dist/analyzer/types.js.map +1 -1
  20. package/dist/backgroundAnalysis.js +3 -1
  21. package/dist/backgroundAnalysis.js.map +1 -1
  22. package/dist/backgroundAnalysisBase.js +1 -1
  23. package/dist/backgroundAnalysisBase.js.map +1 -1
  24. package/dist/backgroundThreadBase.d.ts +2 -2
  25. package/dist/common/collectionUtils.d.ts +2 -2
  26. package/dist/common/collectionUtils.js.map +1 -1
  27. package/dist/common/core.d.ts +8 -3
  28. package/dist/common/core.js.map +1 -1
  29. package/dist/common/envVarUtils.js.map +1 -1
  30. package/dist/languageServerBase.js +20 -16
  31. package/dist/languageServerBase.js.map +1 -1
  32. package/dist/languageService/autoImporter.d.ts +7 -4
  33. package/dist/languageService/autoImporter.js +13 -10
  34. package/dist/languageService/autoImporter.js.map +1 -1
  35. package/dist/languageService/completionProvider.d.ts +1 -0
  36. package/dist/languageService/completionProvider.js +22 -17
  37. package/dist/languageService/completionProvider.js.map +1 -1
  38. package/dist/localization/localize.d.ts +1 -1
  39. package/dist/localization/localize.js +2 -2
  40. package/dist/localization/localize.js.map +1 -1
  41. package/dist/localization/package.nls.cs.json +4 -3
  42. package/dist/localization/package.nls.de.json +3 -2
  43. package/dist/localization/package.nls.es.json +3 -2
  44. package/dist/localization/package.nls.fr.json +3 -2
  45. package/dist/localization/package.nls.it.json +3 -2
  46. package/dist/localization/package.nls.ja.json +3 -2
  47. package/dist/localization/package.nls.ko.json +3 -2
  48. package/dist/localization/package.nls.pl.json +3 -2
  49. package/dist/localization/package.nls.pt-br.json +4 -3
  50. package/dist/localization/package.nls.qps-ploc.json +1 -0
  51. package/dist/localization/package.nls.ru.json +3 -2
  52. package/dist/localization/package.nls.tr.json +3 -2
  53. package/dist/localization/package.nls.zh-cn.json +3 -2
  54. package/dist/localization/package.nls.zh-tw.json +3 -2
  55. package/dist/parser/parseNodes.d.ts +3 -1
  56. package/dist/parser/parseNodes.js +3 -1
  57. package/dist/parser/parseNodes.js.map +1 -1
  58. package/dist/parser/parser.js +14 -6
  59. package/dist/parser/parser.js.map +1 -1
  60. package/dist/tests/completions.test.js +80 -0
  61. package/dist/tests/completions.test.js.map +1 -1
  62. package/dist/tests/languageServer.test.js +39 -4
  63. package/dist/tests/languageServer.test.js.map +1 -1
  64. package/dist/tests/lsp/languageServer.js +19 -3
  65. package/dist/tests/lsp/languageServer.js.map +1 -1
  66. package/dist/tests/typeEvaluator2.test.js +4 -0
  67. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  68. package/dist/tests/typeEvaluator3.test.js +4 -0
  69. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  70. package/dist/tests/typeEvaluator6.test.js +4 -0
  71. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  72. package/dist/tests/typeEvaluator8.test.js +1 -1
  73. package/package.json +4 -4
@@ -575,7 +575,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
575
575
  else {
576
576
  let diagAddendum = new diagnostic_1.DiagnosticAddendum();
577
577
  let returnTypeMatches = false;
578
- if (this._evaluator.assignType(declaredReturnType, returnType, diagAddendum, new typeVarContext_1.TypeVarContext(),
578
+ if (this._evaluator.assignType(declaredReturnType, returnType, diagAddendum,
579
+ /* destTypeVarContext */ undefined,
579
580
  /* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
580
581
  returnTypeMatches = true;
581
582
  }
@@ -2084,82 +2085,91 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2084
2085
  }
2085
2086
  _reportInvalidOverload(name, symbol) {
2086
2087
  const typedDecls = symbol.getTypedDeclarations();
2087
- if (typedDecls.length >= 1) {
2088
- const primaryDecl = typedDecls[0];
2089
- if (primaryDecl.type === 5 /* DeclarationType.Function */) {
2090
- const type = this._evaluator.getEffectiveTypeOfSymbol(symbol);
2091
- const overloadedFunctions = (0, types_1.isOverloadedFunction)(type)
2092
- ? types_1.OverloadedFunctionType.getOverloads(type)
2093
- : (0, types_1.isFunction)(type) && types_1.FunctionType.isOverloaded(type)
2094
- ? [type]
2095
- : [];
2096
- if (overloadedFunctions.length === 1) {
2097
- // There should never be a single overload.
2098
- this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.name);
2099
- }
2100
- // If the file is not a stub and this is the first overload,
2101
- // verify that there is an implementation.
2102
- if (!this._fileInfo.isStubFile && overloadedFunctions.length > 0) {
2103
- let implementationFunction;
2104
- let exemptMissingImplementation = false;
2105
- if ((0, types_1.isOverloadedFunction)(type)) {
2106
- implementationFunction = types_1.OverloadedFunctionType.getImplementation(type);
2107
- // If the implementation has no name, it was synthesized probably by a
2108
- // decorator that used a callable with a ParamSpec that captured the
2109
- // overloaded signature. We'll exempt it from this check.
2110
- const overloads = types_1.OverloadedFunctionType.getOverloads(type);
2111
- if (overloads.length > 0 && overloads[0].details.name === '') {
2112
- exemptMissingImplementation = true;
2113
- }
2114
- }
2115
- else if ((0, types_1.isFunction)(type) && !types_1.FunctionType.isOverloaded(type)) {
2116
- implementationFunction = type;
2088
+ if (typedDecls.length === 0) {
2089
+ return;
2090
+ }
2091
+ const primaryDecl = typedDecls[0];
2092
+ if (primaryDecl.type !== 5 /* DeclarationType.Function */) {
2093
+ return;
2094
+ }
2095
+ const type = this._evaluator.getEffectiveTypeOfSymbol(symbol);
2096
+ const overloadedFunctions = (0, types_1.isOverloadedFunction)(type)
2097
+ ? types_1.OverloadedFunctionType.getOverloads(type)
2098
+ : (0, types_1.isFunction)(type) && types_1.FunctionType.isOverloaded(type)
2099
+ ? [type]
2100
+ : [];
2101
+ // If the implementation has no name, it was synthesized probably by a
2102
+ // decorator that used a callable with a ParamSpec that captured the
2103
+ // overloaded signature. We'll exempt it from this check.
2104
+ if ((0, types_1.isOverloadedFunction)(type)) {
2105
+ const overloads = types_1.OverloadedFunctionType.getOverloads(type);
2106
+ if (overloads.length > 0 && overloads[0].details.name === '') {
2107
+ return;
2108
+ }
2109
+ }
2110
+ else if ((0, types_1.isFunction)(type)) {
2111
+ if (type.details.name === '') {
2112
+ return;
2113
+ }
2114
+ }
2115
+ if (overloadedFunctions.length === 1) {
2116
+ // There should never be a single overload.
2117
+ this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.singleOverload().format({ name }), primaryDecl.node.name);
2118
+ }
2119
+ // If the file is not a stub and this is the first overload,
2120
+ // verify that there is an implementation.
2121
+ if (this._fileInfo.isStubFile || overloadedFunctions.length === 0) {
2122
+ return;
2123
+ }
2124
+ let implementationFunction;
2125
+ if ((0, types_1.isOverloadedFunction)(type)) {
2126
+ implementationFunction = types_1.OverloadedFunctionType.getImplementation(type);
2127
+ }
2128
+ else if ((0, types_1.isFunction)(type) && !types_1.FunctionType.isOverloaded(type)) {
2129
+ implementationFunction = type;
2130
+ }
2131
+ if (!implementationFunction) {
2132
+ const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(primaryDecl.node);
2133
+ if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
2134
+ const classType = this._evaluator.getTypeOfClass(containingClassNode);
2135
+ if (classType) {
2136
+ if (types_1.ClassType.isProtocolClass(classType.classType)) {
2137
+ return;
2117
2138
  }
2118
- if (!implementationFunction) {
2119
- const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(primaryDecl.node);
2120
- if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
2121
- const classType = this._evaluator.getTypeOfClass(containingClassNode);
2122
- if (classType) {
2123
- if (types_1.ClassType.isProtocolClass(classType.classType)) {
2124
- exemptMissingImplementation = true;
2125
- }
2126
- else if (types_1.ClassType.supportsAbstractMethods(classType.classType)) {
2127
- if ((0, types_1.isOverloadedFunction)(type) &&
2128
- types_1.OverloadedFunctionType.getOverloads(type).every((overload) => types_1.FunctionType.isAbstractMethod(overload))) {
2129
- exemptMissingImplementation = true;
2130
- }
2131
- }
2132
- }
2133
- }
2134
- // If this is a method within a protocol class, don't require that
2135
- // there is an implementation.
2136
- if (!exemptMissingImplementation) {
2137
- this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportNoOverloadImplementation, localize_1.LocMessage.overloadWithoutImplementation().format({
2138
- name: primaryDecl.node.name.value,
2139
- }), primaryDecl.node.name);
2139
+ if (types_1.ClassType.supportsAbstractMethods(classType.classType)) {
2140
+ if ((0, types_1.isOverloadedFunction)(type) &&
2141
+ types_1.OverloadedFunctionType.getOverloads(type).every((overload) => types_1.FunctionType.isAbstractMethod(overload))) {
2142
+ return;
2140
2143
  }
2141
2144
  }
2142
- else if ((0, types_1.isOverloadedFunction)(type)) {
2143
- // Verify that all overload signatures are assignable to implementation signature.
2144
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
2145
- var _a, _b, _c, _d;
2146
- const diag = new diagnostic_1.DiagnosticAddendum();
2147
- if (!this._isLegalOverloadImplementation(overload, implementationFunction, diag)) {
2148
- if (implementationFunction.details.declaration) {
2149
- const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadImplementationMismatch().format({
2150
- name,
2151
- index: index + 1,
2152
- }) + diag.getString(), implementationFunction.details.declaration.node.name);
2153
- if (diagnostic && overload.details.declaration) {
2154
- diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), (_b = (_a = overload.details.declaration) === null || _a === void 0 ? void 0 : _a.uri) !== null && _b !== void 0 ? _b : primaryDecl.uri, (_d = (_c = overload.details.declaration) === null || _c === void 0 ? void 0 : _c.range) !== null && _d !== void 0 ? _d : primaryDecl.range);
2155
- }
2156
- }
2157
- }
2158
- });
2159
- }
2160
2145
  }
2161
2146
  }
2147
+ // If this is a method within a protocol class, don't require that
2148
+ // there is an implementation.
2149
+ this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportNoOverloadImplementation, localize_1.LocMessage.overloadWithoutImplementation().format({
2150
+ name: primaryDecl.node.name.value,
2151
+ }), primaryDecl.node.name);
2152
+ return;
2162
2153
  }
2154
+ if (!(0, types_1.isOverloadedFunction)(type)) {
2155
+ return;
2156
+ }
2157
+ // Verify that all overload signatures are assignable to implementation signature.
2158
+ types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
2159
+ var _a, _b, _c, _d;
2160
+ const diag = new diagnostic_1.DiagnosticAddendum();
2161
+ if (!this._isLegalOverloadImplementation(overload, implementationFunction, diag)) {
2162
+ if (implementationFunction.details.declaration) {
2163
+ const diagnostic = this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInconsistentOverload, localize_1.LocMessage.overloadImplementationMismatch().format({
2164
+ name,
2165
+ index: index + 1,
2166
+ }) + diag.getString(), implementationFunction.details.declaration.node.name);
2167
+ if (diagnostic && overload.details.declaration) {
2168
+ diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadSignature(), (_b = (_a = overload.details.declaration) === null || _a === void 0 ? void 0 : _a.uri) !== null && _b !== void 0 ? _b : primaryDecl.uri, (_d = (_c = overload.details.declaration) === null || _c === void 0 ? void 0 : _c.range) !== null && _d !== void 0 ? _d : primaryDecl.range);
2169
+ }
2170
+ }
2171
+ }
2172
+ });
2163
2173
  }
2164
2174
  _reportMultipleFinalDeclarations(name, symbol, scopeType) {
2165
2175
  if (!this._evaluator.isFinalVariable(symbol)) {