@zzzen/pyright-internal 1.2.0-dev.20241124 → 1.2.0-dev.20241208

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 (33) hide show
  1. package/dist/analyzer/checker.d.ts +2 -0
  2. package/dist/analyzer/checker.js +52 -1
  3. package/dist/analyzer/checker.js.map +1 -1
  4. package/dist/analyzer/dataClasses.js +38 -13
  5. package/dist/analyzer/dataClasses.js.map +1 -1
  6. package/dist/analyzer/decorators.js +6 -1
  7. package/dist/analyzer/decorators.js.map +1 -1
  8. package/dist/analyzer/packageTypeVerifier.js +2 -1
  9. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  10. package/dist/analyzer/parseTreeUtils.d.ts +0 -1
  11. package/dist/analyzer/parseTreeUtils.js +0 -8
  12. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  13. package/dist/analyzer/typeEvaluator.js +64 -19
  14. package/dist/analyzer/typeEvaluator.js.map +1 -1
  15. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -2
  16. package/dist/analyzer/typeUtils.js +9 -0
  17. package/dist/analyzer/typeUtils.js.map +1 -1
  18. package/dist/localization/localize.d.ts +1 -0
  19. package/dist/localization/localize.js +1 -0
  20. package/dist/localization/localize.js.map +1 -1
  21. package/dist/localization/package.nls.en-us.json +4 -0
  22. package/dist/parser/stringTokenUtils.js +12 -5
  23. package/dist/parser/stringTokenUtils.js.map +1 -1
  24. package/dist/tests/typeEvaluator3.test.js +10 -0
  25. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  26. package/dist/tests/typeEvaluator4.test.js +16 -0
  27. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  28. package/dist/tests/typeEvaluator6.test.js +1 -1
  29. package/dist/tests/typeEvaluator7.test.js +4 -0
  30. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  31. package/dist/tests/typeEvaluator8.test.js +5 -1
  32. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  33. package/package.json +1 -1
@@ -97,6 +97,8 @@ export declare class Checker extends ParseTreeWalker {
97
97
  private _validateSymbolTables;
98
98
  private _reportInvalidOverload;
99
99
  private _reportFinalInLoop;
100
+ private _reportOverwriteOfImportedFinal;
101
+ private _reportOverwriteOfBuiltinsFinal;
100
102
  private _reportMultipleFinalDeclarations;
101
103
  private _reportMultipleTypeAliasDeclarations;
102
104
  private _reportIncompatibleDeclarations;
@@ -862,7 +862,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
862
862
  }
863
863
  unescapedResult.unescapeErrors.forEach((error) => {
864
864
  if (error.errorType === 0 /* UnescapeErrorType.InvalidEscapeSequence */) {
865
- this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidStringEscapeSequence, localize_1.LocMessage.stringUnsupportedEscape(), { start: start + error.offset, length: error.length });
865
+ this._evaluator.addDiagnosticForTextRange(this._fileInfo, diagnosticRules_1.DiagnosticRule.reportInvalidStringEscapeSequence, node.d.strings.some((string) => (string.d.token.flags & 32 /* StringTokenFlags.Bytes */) !== 0)
866
+ ? localize_1.LocMessage.bytesUnsupportedEscape()
867
+ : localize_1.LocMessage.stringUnsupportedEscape(), { start: start + error.offset, length: error.length });
866
868
  }
867
869
  });
868
870
  // Prior to Python 3.12, it was not allowed to include a slash in an f-string.
@@ -2056,6 +2058,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2056
2058
  scope.symbolTable.forEach((symbol, name) => {
2057
2059
  this._conditionallyReportUnusedSymbol(name, symbol, scope.type, dependentFileInfo);
2058
2060
  this._reportIncompatibleDeclarations(name, symbol);
2061
+ this._reportOverwriteOfImportedFinal(name, symbol);
2062
+ this._reportOverwriteOfBuiltinsFinal(name, symbol, scope);
2059
2063
  this._reportMultipleFinalDeclarations(name, symbol, scope.type);
2060
2064
  this._reportFinalInLoop(symbol);
2061
2065
  this._reportMultipleTypeAliasDeclarations(name, symbol);
@@ -2187,6 +2191,53 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2187
2191
  this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalInLoop(), decls[0].node);
2188
2192
  }
2189
2193
  }
2194
+ // If a variable that is marked Final in one module is imported by another
2195
+ // module, an attempt to overwrite the imported symbol should generate an
2196
+ // error.
2197
+ _reportOverwriteOfImportedFinal(name, symbol) {
2198
+ if (this._evaluator.isFinalVariable(symbol)) {
2199
+ return;
2200
+ }
2201
+ const decls = symbol.getDeclarations();
2202
+ const finalImportDecl = decls.find((decl) => {
2203
+ if (decl.type === 8 /* DeclarationType.Alias */) {
2204
+ const resolvedDecl = this._evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
2205
+ if (resolvedDecl && (0, declaration_1.isVariableDeclaration)(resolvedDecl) && resolvedDecl.isFinal) {
2206
+ return true;
2207
+ }
2208
+ }
2209
+ return false;
2210
+ });
2211
+ if (!finalImportDecl) {
2212
+ return;
2213
+ }
2214
+ decls.forEach((decl) => {
2215
+ var _a;
2216
+ if (decl !== finalImportDecl) {
2217
+ this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
2218
+ }
2219
+ });
2220
+ }
2221
+ // If the builtins module (or any implicitly chained module) defines a
2222
+ // Final variable, an attempt to overwrite it should generate an error.
2223
+ _reportOverwriteOfBuiltinsFinal(name, symbol, scope) {
2224
+ if (scope.type !== 4 /* ScopeType.Module */ || !scope.parent) {
2225
+ return;
2226
+ }
2227
+ const shadowedSymbolInfo = scope.parent.lookUpSymbolRecursive(name);
2228
+ if (!shadowedSymbolInfo) {
2229
+ return;
2230
+ }
2231
+ if (!this._evaluator.isFinalVariable(shadowedSymbolInfo.symbol)) {
2232
+ return;
2233
+ }
2234
+ const decls = symbol.getDeclarations();
2235
+ decls.forEach((decl) => {
2236
+ var _a;
2237
+ this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
2238
+ });
2239
+ }
2240
+ // If a variable is marked Final, it should receive only one assigned value.
2190
2241
  _reportMultipleFinalDeclarations(name, symbol, scopeType) {
2191
2242
  if (!this._evaluator.isFinalVariable(symbol)) {
2192
2243
  return;