@zzzen/pyright-internal 1.2.0-dev.20250817 → 1.2.0-dev.20250824

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 (52) hide show
  1. package/dist/analyzer/binder.js +2 -2
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/commentUtils.js +5 -1
  4. package/dist/analyzer/commentUtils.js.map +1 -1
  5. package/dist/analyzer/importLogger.d.ts +5 -0
  6. package/dist/analyzer/importLogger.js +24 -0
  7. package/dist/analyzer/importLogger.js.map +1 -0
  8. package/dist/analyzer/importResolver.d.ts +7 -6
  9. package/dist/analyzer/importResolver.js +127 -134
  10. package/dist/analyzer/importResolver.js.map +1 -1
  11. package/dist/analyzer/importResult.d.ts +2 -2
  12. package/dist/analyzer/importStatementUtils.js +6 -4
  13. package/dist/analyzer/importStatementUtils.js.map +1 -1
  14. package/dist/analyzer/program.js +7 -6
  15. package/dist/analyzer/program.js.map +1 -1
  16. package/dist/analyzer/pythonPathUtils.d.ts +2 -1
  17. package/dist/analyzer/pythonPathUtils.js +14 -14
  18. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  19. package/dist/analyzer/service.js +9 -10
  20. package/dist/analyzer/service.js.map +1 -1
  21. package/dist/analyzer/sourceFile.js +3 -2
  22. package/dist/analyzer/sourceFile.js.map +1 -1
  23. package/dist/analyzer/typeEvaluator.js +2 -1
  24. package/dist/analyzer/typeEvaluator.js.map +1 -1
  25. package/dist/common/configOptions.js +4 -3
  26. package/dist/common/configOptions.js.map +1 -1
  27. package/dist/common/fullAccessHost.d.ts +5 -3
  28. package/dist/common/fullAccessHost.js +68 -19
  29. package/dist/common/fullAccessHost.js.map +1 -1
  30. package/dist/common/host.d.ts +11 -6
  31. package/dist/common/host.js +7 -4
  32. package/dist/common/host.js.map +1 -1
  33. package/dist/common/uri/memoization.js +19 -8
  34. package/dist/common/uri/memoization.js.map +1 -1
  35. package/dist/common/uri/webUri.js +1 -1
  36. package/dist/common/uri/webUri.js.map +1 -1
  37. package/dist/languageService/completionProvider.js +1 -1
  38. package/dist/languageService/completionProvider.js.map +1 -1
  39. package/dist/parser/parser.d.ts +1 -1
  40. package/dist/parser/parser.js +1 -1
  41. package/dist/parser/parser.js.map +1 -1
  42. package/dist/parser/tokenizer.js +1 -1
  43. package/dist/parser/tokenizer.js.map +1 -1
  44. package/dist/tests/harness/fourslash/testLanguageService.d.ts +1 -1
  45. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  46. package/dist/tests/harness/testAccessHost.d.ts +2 -1
  47. package/dist/tests/harness/testAccessHost.js +1 -1
  48. package/dist/tests/harness/testAccessHost.js.map +1 -1
  49. package/dist/tests/lsp/languageServerTestUtils.d.ts +4 -3
  50. package/dist/tests/lsp/languageServerTestUtils.js +3 -3
  51. package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
  52. package/package.json +1 -1
@@ -48,6 +48,7 @@ const stringUtils_1 = require("../common/stringUtils");
48
48
  const uri_1 = require("../common/uri/uri");
49
49
  const uriUtils_1 = require("../common/uri/uriUtils");
50
50
  const tokenizer_1 = require("../parser/tokenizer");
51
+ const importLogger_1 = require("./importLogger");
51
52
  const importStatementUtils_1 = require("./importStatementUtils");
52
53
  const parentDirectoryCache_1 = require("./parentDirectoryCache");
53
54
  const pyTypedUtils_1 = require("./pyTypedUtils");
@@ -91,7 +92,7 @@ class ImportResolver {
91
92
  this._cachedEntriesForPath = new Map();
92
93
  this._cachedFilesForPath = new Map();
93
94
  this._cachedDirExistenceForRoot = new Map();
94
- this.cachedParentImportResults = new parentDirectoryCache_1.ParentDirectoryCache(() => this.getPythonSearchPaths([]));
95
+ this.cachedParentImportResults = new parentDirectoryCache_1.ParentDirectoryCache(() => this.getPythonSearchPaths());
95
96
  }
96
97
  get fileSystem() {
97
98
  return this.serviceProvider.fs();
@@ -245,12 +246,11 @@ class ImportResolver {
245
246
  return (0, collectionUtils_1.getOrAdd)(cache, key, () => this._getModuleNameForImport(fileUri, execEnv, allowInvalidModuleName, detectPyTyped));
246
247
  }
247
248
  getTypeshedStdLibPath(execEnv) {
248
- const unused = [];
249
- return this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, unused);
249
+ return this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform,
250
+ /* logger */ undefined);
250
251
  }
251
252
  getTypeshedThirdPartyPath(execEnv) {
252
- const unused = [];
253
- return this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, unused);
253
+ return this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath);
254
254
  }
255
255
  isStdlibModule(module, execEnv) {
256
256
  if (!this._stdlibModules) {
@@ -259,9 +259,8 @@ class ImportResolver {
259
259
  return this._stdlibModules.has(module.nameParts.join('.'));
260
260
  }
261
261
  getImportRoots(execEnv, forLogging = false) {
262
- const importFailureInfo = [];
263
262
  const roots = [];
264
- const stdTypeshed = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo);
263
+ const stdTypeshed = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform);
265
264
  if (stdTypeshed) {
266
265
  roots.push(stdTypeshed);
267
266
  }
@@ -277,20 +276,20 @@ class ImportResolver {
277
276
  // There's one path for each third party package, which blows up logging.
278
277
  // Just get the root directly and show it with `...` to indicate that this
279
278
  // is where the third party folder is in the roots.
280
- const thirdPartyRoot = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
279
+ const thirdPartyRoot = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath);
281
280
  if (thirdPartyRoot) {
282
281
  roots.push(thirdPartyRoot.resolvePaths('...'));
283
282
  }
284
283
  }
285
284
  else {
286
- const thirdPartyPaths = this._getThirdPartyTypeshedPackageRoots(importFailureInfo);
285
+ const thirdPartyPaths = this._getThirdPartyTypeshedPackageRoots();
287
286
  (0, collectionUtils_1.appendArray)(roots, thirdPartyPaths);
288
287
  }
289
- const typeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
288
+ const typeshedPathEx = this.getTypeshedPathEx(execEnv);
290
289
  if (typeshedPathEx) {
291
290
  roots.push(typeshedPathEx);
292
291
  }
293
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
292
+ const pythonSearchPaths = this.getPythonSearchPaths();
294
293
  if (pythonSearchPaths.length > 0) {
295
294
  (0, collectionUtils_1.appendArray)(roots, pythonSearchPaths);
296
295
  }
@@ -304,15 +303,14 @@ class ImportResolver {
304
303
  return false;
305
304
  }
306
305
  const ps = this.partialStubs;
307
- const ignored = [];
308
306
  const paths = [];
309
- const typeshedPathEx = this.getTypeshedPathEx(execEnv, ignored);
307
+ const typeshedPathEx = this.getTypeshedPathEx(execEnv);
310
308
  // Add paths to search stub packages.
311
309
  addPaths(this._configOptions.stubPath);
312
310
  addPaths(execEnv.root ?? this._configOptions.projectRoot);
313
311
  execEnv.extraPaths.forEach((p) => addPaths(p));
314
312
  addPaths(typeshedPathEx);
315
- this.getPythonSearchPaths(ignored).forEach((p) => addPaths(p));
313
+ this.getPythonSearchPaths().forEach((p) => addPaths(p));
316
314
  this.partialStubs.processPartialStubPackages(paths, this.getImportRoots(execEnv), typeshedPathEx);
317
315
  this._invalidateFileSystemCache();
318
316
  return true;
@@ -323,27 +321,25 @@ class ImportResolver {
323
321
  paths.push(path);
324
322
  }
325
323
  }
326
- getPythonSearchPaths(importFailureInfo) {
324
+ getPythonSearchPaths(importLogger) {
327
325
  // Find the site packages for the configured virtual environment.
328
326
  if (!this._cachedPythonSearchPaths) {
329
- const info = [];
330
- const paths = (PythonPathUtils.findPythonSearchPaths(this.fileSystem, this._configOptions, this.host, info) || []).map((p) => this.fileSystem.realCasePath(p));
327
+ const paths = (PythonPathUtils.findPythonSearchPaths(this.fileSystem, this._configOptions, this.host, importLogger) ||
328
+ []).map((p) => this.fileSystem.realCasePath(p));
331
329
  // Remove duplicates (yes, it happens).
332
- this._cachedPythonSearchPaths = { paths: Array.from(new Set(paths)), failureInfo: info };
330
+ this._cachedPythonSearchPaths = { paths: Array.from(new Set(paths)), failureInfo: importLogger };
333
331
  }
334
- // Make sure we cache the logs as well so we can find out why search path failed.
335
- importFailureInfo.push(...this._cachedPythonSearchPaths.failureInfo);
336
332
  return this._cachedPythonSearchPaths.paths;
337
333
  }
338
334
  getTypeshedStdlibExcludeList(customTypeshedPath, pythonVersion, pythonPlatform) {
339
- const unused = [];
340
- const typeshedStdlibPath = this._getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform, unused);
335
+ const typeshedStdlibPath = this._getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform,
336
+ /* importLogger */ undefined);
341
337
  const excludes = [];
342
338
  if (!typeshedStdlibPath) {
343
339
  return excludes;
344
340
  }
345
341
  if (!this._cachedTypeshedStdLibModuleVersionInfo) {
346
- this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath, []);
342
+ this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath);
347
343
  }
348
344
  this._cachedTypeshedStdLibModuleVersionInfo.forEach((versionInfo, moduleName) => {
349
345
  let shouldExcludeModule = false;
@@ -379,7 +375,7 @@ class ImportResolver {
379
375
  }
380
376
  // Intended to be overridden by subclasses to provide additional stub
381
377
  // path capabilities. Return undefined if no extra stub path were found.
382
- getTypeshedPathEx(execEnv, importFailureInfo) {
378
+ getTypeshedPathEx(execEnv, importLogger) {
383
379
  return undefined;
384
380
  }
385
381
  readdirEntriesCached(uri) {
@@ -402,8 +398,7 @@ class ImportResolver {
402
398
  // returns undefined.
403
399
  resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor) {
404
400
  const importName = formatImportName(moduleDescriptor);
405
- const importFailureInfo = [];
406
- const importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
401
+ const importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor);
407
402
  if (importResult.isImportFound || moduleDescriptor.leadingDots > 0) {
408
403
  return importResult;
409
404
  }
@@ -421,12 +416,13 @@ class ImportResolver {
421
416
  if (!this.cachedParentImportResults.checkValidPath(this.fileSystem, sourceFileUri, root)) {
422
417
  return importResult;
423
418
  }
424
- const localImportFailureInfo = [`Attempting to resolve using local imports: ${importName}`];
419
+ const importLogger = this._configOptions.verboseOutput ? new importLogger_1.ImportLogger() : undefined;
420
+ importLogger?.log(`Attempting to resolve using local imports: ${importName}`);
425
421
  const importPath = { importPath: undefined };
426
422
  // Going up the given folder one by one until we can resolve the import.
427
423
  let current = origin;
428
424
  while (this._shouldWalkUp(current, root, execEnv) && current) {
429
- const result = this.resolveAbsoluteImport(sourceFileUri, current, execEnv, moduleDescriptor, importName, localImportFailureInfo,
425
+ const result = this.resolveAbsoluteImport(sourceFileUri, current, execEnv, moduleDescriptor, importName, importLogger,
430
426
  /* allowPartial */ undefined,
431
427
  /* allowNativeLib */ undefined,
432
428
  /* useStubPackage */ false,
@@ -447,9 +443,9 @@ class ImportResolver {
447
443
  if (current) {
448
444
  this.cachedParentImportResults.checked(current, importName, importPath);
449
445
  }
450
- if (this._configOptions.verboseOutput) {
446
+ if (importLogger) {
451
447
  const console = this.serviceProvider.console();
452
- localImportFailureInfo.forEach((diag) => console.log(diag));
448
+ importLogger.getLogs().forEach((diag) => console.log(diag));
453
449
  }
454
450
  return importResult;
455
451
  }
@@ -509,12 +505,12 @@ class ImportResolver {
509
505
  }
510
506
  // Follows import resolution algorithm defined in PEP-420:
511
507
  // https://www.python.org/dev/peps/pep-0420/
512
- resolveAbsoluteImport(sourceFileUri, rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial = false, allowNativeLib = false, useStubPackage = false, allowPyi = true, lookForPyTyped = false) {
508
+ resolveAbsoluteImport(sourceFileUri, rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial = false, allowNativeLib = false, useStubPackage = false, allowPyi = true, lookForPyTyped = false) {
513
509
  if (allowPyi && useStubPackage) {
514
510
  // Look for packaged stubs first. PEP 561 indicates that package authors can ship
515
511
  // their stubs separately from their package implementation by appending the string
516
512
  // '-stubs' to its top - level directory name. We'll look there first.
517
- const importResult = this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial,
513
+ const importResult = this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial,
518
514
  /* allowNativeLib */ false,
519
515
  /* useStubPackage */ true,
520
516
  /* allowPyi */ true,
@@ -528,19 +524,19 @@ class ImportResolver {
528
524
  }
529
525
  }
530
526
  }
531
- return this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial, allowNativeLib,
527
+ return this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial, allowNativeLib,
532
528
  /* useStubPackage */ false, allowPyi, lookForPyTyped);
533
529
  }
534
530
  // Intended to be overridden by subclasses to provide additional stub
535
531
  // resolving capabilities. Return undefined if no stubs were found for
536
532
  // this import.
537
- resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo = [], allowPyi = true) {
533
+ resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger, allowPyi = true) {
538
534
  return undefined;
539
535
  }
540
536
  // Intended to be overridden by subclasses to provide additional stub
541
537
  // resolving capabilities for native (compiled) modules. Returns undefined
542
538
  // if no stubs were found for this import.
543
- resolveNativeImportEx(libraryFileUri, importName, importFailureInfo = []) {
539
+ resolveNativeImportEx(libraryFileUri, importName, importLogger) {
544
540
  return undefined;
545
541
  }
546
542
  getNativeModuleName(uri) {
@@ -555,13 +551,13 @@ class ImportResolver {
555
551
  filterImplicitImports(importResult, importedSymbols) {
556
552
  if (importedSymbols === undefined) {
557
553
  const newImportResult = Object.assign({}, importResult);
558
- newImportResult.filteredImplicitImports = new Map();
554
+ newImportResult.filteredImplicitImports = undefined;
559
555
  return newImportResult;
560
556
  }
561
- if (importedSymbols.size === 0) {
557
+ if (importedSymbols === undefined || importedSymbols.size === 0) {
562
558
  return importResult;
563
559
  }
564
- if (importResult.implicitImports.size === 0) {
560
+ if (importResult.implicitImports === undefined || importResult.implicitImports.size === 0) {
565
561
  return importResult;
566
562
  }
567
563
  const filteredImplicitImports = new Map();
@@ -612,7 +608,7 @@ class ImportResolver {
612
608
  // Try resolving resolving native lib to a custom stub.
613
609
  if (isNativeLib) {
614
610
  const nativeLibPath = filePath;
615
- const nativeStubPath = this.resolveNativeImportEx(nativeLibPath, `${importingModuleName}.${strippedFileName}`, []);
611
+ const nativeStubPath = this.resolveNativeImportEx(nativeLibPath, `${importingModuleName}.${strippedFileName}`);
616
612
  if (nativeStubPath) {
617
613
  implicitImport.uri = nativeStubPath;
618
614
  implicitImport.isNativeLib = false;
@@ -648,9 +644,9 @@ class ImportResolver {
648
644
  }
649
645
  }
650
646
  }
651
- return implicitImportMap;
647
+ return implicitImportMap.size > 0 ? implicitImportMap : undefined;
652
648
  }
653
- _resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo) {
649
+ _resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importLogger) {
654
650
  const fromUserFile = (0, configOptions_1.matchFileSpecs)(this._configOptions, sourceFileUri);
655
651
  const notFoundResult = {
656
652
  importName,
@@ -660,13 +656,13 @@ class ImportResolver {
660
656
  isNamespacePackage: false,
661
657
  isInitFilePresent: false,
662
658
  isStubPackage: false,
663
- importFailureInfo,
659
+ importFailureInfo: importLogger?.getLogs(),
664
660
  resolvedUris: [],
665
661
  importType: 2 /* ImportType.Local */,
666
662
  isStubFile: false,
667
663
  isNativeLib: false,
668
- implicitImports: new Map(),
669
- filteredImplicitImports: new Map(),
664
+ implicitImports: undefined,
665
+ filteredImplicitImports: undefined,
670
666
  nonStubImportResult: undefined,
671
667
  };
672
668
  this.ensurePartialStubPackages(execEnv);
@@ -676,7 +672,7 @@ class ImportResolver {
676
672
  if (cachedResults) {
677
673
  return cachedResults;
678
674
  }
679
- const relativeImport = this._resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo);
675
+ const relativeImport = this._resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger);
680
676
  if (relativeImport) {
681
677
  relativeImport.isRelative = true;
682
678
  return this.addResultsToCache(sourceFileUri, execEnv, importName, relativeImport, moduleDescriptor, fromUserFile);
@@ -712,7 +708,6 @@ class ImportResolver {
712
708
  /* moduleDescriptor */ undefined, fromUserFile);
713
709
  }
714
710
  _getCompletionSuggestionsStrict(sourceFileUri, execEnv, moduleDescriptor) {
715
- const importFailureInfo = [];
716
711
  const suggestions = new Map();
717
712
  // Is it a relative import?
718
713
  if (moduleDescriptor.leadingDots > 0) {
@@ -737,7 +732,7 @@ class ImportResolver {
737
732
  // Check for a typeshed file.
738
733
  this._getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, false, suggestions);
739
734
  // Look for the import in the list of third-party packages.
740
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
735
+ const pythonSearchPaths = this.getPythonSearchPaths();
741
736
  for (const searchPath of pythonSearchPaths) {
742
737
  this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, searchPath, moduleDescriptor, suggestions);
743
738
  }
@@ -750,14 +745,13 @@ class ImportResolver {
750
745
  let isLocalTypingsFile = false;
751
746
  let isThirdPartyPyTypedPresent = false;
752
747
  let isTypeshedFile = false;
753
- const importFailureInfo = [];
754
748
  // If we cannot find a fully-qualified module name with legal characters,
755
749
  // look for one with invalid characters (e.g. "-"). This is important to
756
750
  // differentiate between different modules in a project in case they
757
751
  // declare types with the same (local) name.
758
752
  let moduleNameWithInvalidCharacters;
759
753
  // Is this a stdlib typeshed path?
760
- const stdLibTypeshedPath = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo);
754
+ const stdLibTypeshedPath = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform);
761
755
  if (stdLibTypeshedPath) {
762
756
  moduleName = getModuleNameFromPath(stdLibTypeshedPath, fileUri);
763
757
  if (moduleName) {
@@ -766,7 +760,7 @@ class ImportResolver {
766
760
  nameParts: moduleName.split('.'),
767
761
  importedSymbols: undefined,
768
762
  };
769
- if (this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, [])) {
763
+ if (this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform)) {
770
764
  return {
771
765
  moduleName,
772
766
  importType,
@@ -828,7 +822,7 @@ class ImportResolver {
828
822
  }
829
823
  }
830
824
  // Check for a typeshed file.
831
- const thirdPartyTypeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
825
+ const thirdPartyTypeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath);
832
826
  if (thirdPartyTypeshedPath) {
833
827
  const candidateModuleName = getModuleNameFromPath(thirdPartyTypeshedPath, fileUri,
834
828
  /* stripTopContainerDir */ true);
@@ -840,7 +834,7 @@ class ImportResolver {
840
834
  isTypeshedFile = true;
841
835
  }
842
836
  }
843
- const thirdPartyTypeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
837
+ const thirdPartyTypeshedPathEx = this.getTypeshedPathEx(execEnv);
844
838
  if (thirdPartyTypeshedPathEx) {
845
839
  const candidateModuleName = getModuleNameFromPath(thirdPartyTypeshedPathEx, fileUri);
846
840
  // Does this candidate look better than the previous best module name?
@@ -852,7 +846,7 @@ class ImportResolver {
852
846
  }
853
847
  }
854
848
  // Look for the import in the list of third-party packages.
855
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
849
+ const pythonSearchPaths = this.getPythonSearchPaths();
856
850
  for (const searchPath of pythonSearchPaths) {
857
851
  const candidateModuleNameInfo = _getModuleNameInfoFromPath(searchPath, fileUri);
858
852
  if (candidateModuleNameInfo) {
@@ -912,12 +906,12 @@ class ImportResolver {
912
906
  this._cachedFilesForPath.clear();
913
907
  this._cachedDirExistenceForRoot.clear();
914
908
  }
915
- _resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial, allowNativeLib, useStubPackage, allowPyi, lookForPyTyped) {
909
+ _resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial, allowNativeLib, useStubPackage, allowPyi, lookForPyTyped) {
916
910
  if (useStubPackage) {
917
- importFailureInfo.push(`Attempting to resolve stub package using root path '${rootPath}'`);
911
+ importLogger?.log(`Attempting to resolve stub package using root path '${rootPath}'`);
918
912
  }
919
913
  else {
920
- importFailureInfo.push(`Attempting to resolve using root path '${rootPath}'`);
914
+ importLogger?.log(`Attempting to resolve using root path '${rootPath}'`);
921
915
  }
922
916
  // Starting at the specified path, walk the file system to find the
923
917
  // specified module.
@@ -928,7 +922,7 @@ class ImportResolver {
928
922
  let isStubPackage = false;
929
923
  let isStubFile = false;
930
924
  let isNativeLib = false;
931
- let implicitImports = new Map();
925
+ let implicitImports;
932
926
  let packageDirectory;
933
927
  let pyTypedInfo;
934
928
  // Handle the "from . import XXX" case.
@@ -936,16 +930,16 @@ class ImportResolver {
936
930
  const pyFilePath = dirPath.initPyUri;
937
931
  const pyiFilePath = dirPath.initPyiUri;
938
932
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
939
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
933
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
940
934
  resolvedPaths.push(pyiFilePath);
941
935
  isStubFile = true;
942
936
  }
943
937
  else if (this.fileExistsCached(pyFilePath)) {
944
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
938
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
945
939
  resolvedPaths.push(pyFilePath);
946
940
  }
947
941
  else {
948
- importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
942
+ importLogger?.log(`Partially resolved import with directory '${dirPath}'`);
949
943
  resolvedPaths.push(uri_1.Uri.empty());
950
944
  isNamespacePackage = true;
951
945
  }
@@ -970,7 +964,7 @@ class ImportResolver {
970
964
  const pyiFilePath = dirPath.initPyiUri;
971
965
  isInitFilePresent = false;
972
966
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
973
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
967
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
974
968
  resolvedPaths.push(pyiFilePath);
975
969
  if (isLastPart) {
976
970
  isStubFile = true;
@@ -978,7 +972,7 @@ class ImportResolver {
978
972
  isInitFilePresent = true;
979
973
  }
980
974
  else if (this.fileExistsCached(pyFilePath)) {
981
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
975
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
982
976
  resolvedPaths.push(pyFilePath);
983
977
  isInitFilePresent = true;
984
978
  }
@@ -1005,20 +999,20 @@ class ImportResolver {
1005
999
  const pyiFilePath = dirPath.packageStubUri;
1006
1000
  const fileDirectory = dirPath.getDirectory();
1007
1001
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
1008
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
1002
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
1009
1003
  resolvedPaths.push(pyiFilePath);
1010
1004
  if (isLastPart) {
1011
1005
  isStubFile = true;
1012
1006
  }
1013
1007
  }
1014
1008
  else if (this.fileExistsCached(pyFilePath)) {
1015
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
1009
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
1016
1010
  resolvedPaths.push(pyFilePath);
1017
1011
  }
1018
1012
  else if (allowNativeLib &&
1019
- this._findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths)) {
1013
+ this._findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths)) {
1020
1014
  isNativeLib = true;
1021
- importFailureInfo.push(`Did not find file '${pyiFilePath}' or '${pyFilePath}'`);
1015
+ importLogger?.log(`Did not find file '${pyiFilePath}' or '${pyFilePath}'`);
1022
1016
  }
1023
1017
  else if (foundDirectory) {
1024
1018
  if (!isLastPart) {
@@ -1030,7 +1024,7 @@ class ImportResolver {
1030
1024
  pyTypedInfo = undefined;
1031
1025
  continue;
1032
1026
  }
1033
- importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
1027
+ importLogger?.log(`Partially resolved import with directory '${dirPath}'`);
1034
1028
  resolvedPaths.push(uri_1.Uri.empty());
1035
1029
  if (isLastPart) {
1036
1030
  implicitImports = this.findImplicitImports(importName, dirPath, [pyFilePath, pyiFilePath]);
@@ -1059,7 +1053,7 @@ class ImportResolver {
1059
1053
  isStubPackage,
1060
1054
  isImportFound: importFound,
1061
1055
  isPartlyResolved,
1062
- importFailureInfo,
1056
+ importFailureInfo: importLogger?.getLogs(),
1063
1057
  importType: 2 /* ImportType.Local */,
1064
1058
  resolvedUris: resolvedPaths,
1065
1059
  searchPath: rootPath,
@@ -1094,22 +1088,22 @@ class ImportResolver {
1094
1088
  // are all satisfied by submodules (as listed in the implicit imports).
1095
1089
  _isNamespacePackageResolved(moduleDescriptor, implicitImports) {
1096
1090
  if (moduleDescriptor.importedSymbols) {
1097
- if (!Array.from(moduleDescriptor.importedSymbols.keys()).some((symbol) => implicitImports.has(symbol))) {
1091
+ if (!Array.from(moduleDescriptor.importedSymbols.keys()).some((symbol) => implicitImports?.has(symbol))) {
1098
1092
  return false;
1099
1093
  }
1100
1094
  }
1101
- else if (implicitImports.size === 0) {
1095
+ else if (!implicitImports || implicitImports.size === 0) {
1102
1096
  return false;
1103
1097
  }
1104
1098
  return true;
1105
1099
  }
1106
1100
  _resolveBestAbsoluteImport(sourceFileUri, execEnv, moduleDescriptor, allowPyi) {
1107
1101
  const importName = formatImportName(moduleDescriptor);
1108
- const importFailureInfo = [];
1102
+ const importLogger = this._configOptions.verboseOutput ? new importLogger_1.ImportLogger() : undefined;
1109
1103
  // Check for a local stub file using stubPath.
1110
1104
  if (allowPyi && this._configOptions.stubPath) {
1111
- importFailureInfo.push(`Looking in stubPath '${this._configOptions.stubPath}'`);
1112
- const typingsImport = this.resolveAbsoluteImport(sourceFileUri, this._configOptions.stubPath, execEnv, moduleDescriptor, importName, importFailureInfo,
1105
+ importLogger?.log(`Looking in stubPath '${this._configOptions.stubPath}'`);
1106
+ const typingsImport = this.resolveAbsoluteImport(sourceFileUri, this._configOptions.stubPath, execEnv, moduleDescriptor, importName, importLogger,
1113
1107
  /* allowPartial */ undefined,
1114
1108
  /* allowNativeLib */ false,
1115
1109
  /* useStubPackage */ true, allowPyi,
@@ -1136,8 +1130,8 @@ class ImportResolver {
1136
1130
  let localImport;
1137
1131
  // Look for it in the root directory of the execution environment.
1138
1132
  if (execEnv.root) {
1139
- importFailureInfo.push(`Looking in root directory of execution environment ` + `'${execEnv.root}'`);
1140
- localImport = this.resolveAbsoluteImport(sourceFileUri, execEnv.root, execEnv, moduleDescriptor, importName, importFailureInfo,
1133
+ importLogger?.log(`Looking in root directory of execution environment ` + `'${execEnv.root}'`);
1134
+ localImport = this.resolveAbsoluteImport(sourceFileUri, execEnv.root, execEnv, moduleDescriptor, importName, importLogger,
1141
1135
  /* allowPartial */ undefined,
1142
1136
  /* allowNativeLib */ true,
1143
1137
  /* useStubPackage */ true, allowPyi,
@@ -1145,8 +1139,8 @@ class ImportResolver {
1145
1139
  bestResultSoFar = localImport;
1146
1140
  }
1147
1141
  for (const extraPath of execEnv.extraPaths) {
1148
- importFailureInfo.push(`Looking in extraPath '${extraPath}'`);
1149
- localImport = this.resolveAbsoluteImport(sourceFileUri, extraPath, execEnv, moduleDescriptor, importName, importFailureInfo,
1142
+ importLogger?.log(`Looking in extraPath '${extraPath}'`);
1143
+ localImport = this.resolveAbsoluteImport(sourceFileUri, extraPath, execEnv, moduleDescriptor, importName, importLogger,
1150
1144
  /* allowPartial */ undefined,
1151
1145
  /* allowNativeLib */ true,
1152
1146
  /* useStubPackage */ true, allowPyi,
@@ -1155,20 +1149,20 @@ class ImportResolver {
1155
1149
  }
1156
1150
  // Check for a stdlib typeshed file.
1157
1151
  if (allowPyi && moduleDescriptor.nameParts.length > 0) {
1158
- importFailureInfo.push(`Looking for typeshed stdlib path`);
1152
+ importLogger?.log(`Looking for typeshed stdlib path`);
1159
1153
  const typeshedStdlibImport = this._findTypeshedPath(execEnv, moduleDescriptor, importName,
1160
- /* isStdLib */ true, importFailureInfo);
1154
+ /* isStdLib */ true, importLogger);
1161
1155
  if (typeshedStdlibImport) {
1162
1156
  typeshedStdlibImport.isStdlibTypeshedFile = true;
1163
1157
  return typeshedStdlibImport;
1164
1158
  }
1165
1159
  }
1166
1160
  // Look for the import in the list of third-party packages.
1167
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
1161
+ const pythonSearchPaths = this.getPythonSearchPaths(importLogger);
1168
1162
  if (pythonSearchPaths.length > 0) {
1169
1163
  for (const searchPath of pythonSearchPaths) {
1170
- importFailureInfo.push(`Looking in python search path '${searchPath}'`);
1171
- const thirdPartyImport = this.resolveAbsoluteImport(sourceFileUri, searchPath, execEnv, moduleDescriptor, importName, importFailureInfo,
1164
+ importLogger?.log(`Looking in python search path '${searchPath}'`);
1165
+ const thirdPartyImport = this.resolveAbsoluteImport(sourceFileUri, searchPath, execEnv, moduleDescriptor, importName, importLogger,
1172
1166
  /* allowPartial */ allowPartialResolutionForThirdPartyPackages,
1173
1167
  /* allowNativeLib */ true,
1174
1168
  /* useStubPackage */ true, allowPyi,
@@ -1180,26 +1174,26 @@ class ImportResolver {
1180
1174
  }
1181
1175
  }
1182
1176
  else {
1183
- importFailureInfo.push('No python interpreter search path');
1177
+ importLogger?.log('No python interpreter search path');
1184
1178
  }
1185
1179
  // If a library is fully py.typed, then we have found the best match,
1186
1180
  // unless the execution environment is typeshed itself, in which case
1187
1181
  // we don't want to favor py.typed libraries. Use the typeshed lookup below.
1188
- if (execEnv.root !== this._getTypeshedRoot(this._configOptions.typeshedPath, importFailureInfo)) {
1182
+ if (execEnv.root !== this._getTypeshedRoot(this._configOptions.typeshedPath, importLogger)) {
1189
1183
  if (bestResultSoFar?.pyTypedInfo && !bestResultSoFar.isPartlyResolved) {
1190
1184
  return bestResultSoFar;
1191
1185
  }
1192
1186
  }
1193
1187
  // Call the extensibility hook for subclasses.
1194
- const extraResults = this.resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo, allowPyi);
1188
+ const extraResults = this.resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger, allowPyi);
1195
1189
  if (extraResults) {
1196
1190
  return extraResults;
1197
1191
  }
1198
1192
  // Check for a third-party typeshed file.
1199
1193
  if (allowPyi && moduleDescriptor.nameParts.length > 0) {
1200
- importFailureInfo.push(`Looking for typeshed third-party path`);
1194
+ importLogger?.log(`Looking for typeshed third-party path`);
1201
1195
  const typeshedImport = this._findTypeshedPath(execEnv, moduleDescriptor, importName,
1202
- /* isStdLib */ false, importFailureInfo);
1196
+ /* isStdLib */ false, importLogger);
1203
1197
  if (typeshedImport) {
1204
1198
  typeshedImport.isThirdPartyTypeshedFile = true;
1205
1199
  bestResultSoFar = this._pickBestImport(bestResultSoFar, typeshedImport, moduleDescriptor);
@@ -1301,22 +1295,22 @@ class ImportResolver {
1301
1295
  }
1302
1296
  return bestImportSoFar;
1303
1297
  }
1304
- _findTypeshedPath(execEnv, moduleDescriptor, importName, isStdLib, importFailureInfo) {
1305
- importFailureInfo.push(`Looking for typeshed ${isStdLib ? PythonPathUtils.stdLibFolderName : PythonPathUtils.thirdPartyFolderName} path`);
1298
+ _findTypeshedPath(execEnv, moduleDescriptor, importName, isStdLib, importLogger) {
1299
+ importLogger?.log(`Looking for typeshed ${isStdLib ? PythonPathUtils.stdLibFolderName : PythonPathUtils.thirdPartyFolderName} path`);
1306
1300
  let typeshedPaths;
1307
1301
  if (isStdLib) {
1308
- const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo, moduleDescriptor);
1302
+ const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importLogger, moduleDescriptor);
1309
1303
  if (path) {
1310
1304
  typeshedPaths = [path];
1311
1305
  }
1312
1306
  }
1313
1307
  else {
1314
- typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo);
1308
+ typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importLogger);
1315
1309
  }
1316
1310
  if (typeshedPaths) {
1317
1311
  for (const typeshedPath of typeshedPaths) {
1318
1312
  if (this.dirExistsCached(typeshedPath)) {
1319
- const importInfo = this.resolveAbsoluteImport(undefined, typeshedPath, execEnv, moduleDescriptor, importName, importFailureInfo);
1313
+ const importInfo = this.resolveAbsoluteImport(undefined, typeshedPath, execEnv, moduleDescriptor, importName, importLogger);
1320
1314
  if (importInfo.isImportFound) {
1321
1315
  let importType = isStdLib ? 0 /* ImportType.BuiltIn */ : 1 /* ImportType.ThirdParty */;
1322
1316
  // Handle 'typing_extensions' as a special case because it's
@@ -1330,7 +1324,7 @@ class ImportResolver {
1330
1324
  }
1331
1325
  }
1332
1326
  }
1333
- importFailureInfo.push(`Typeshed path not found`);
1327
+ importLogger?.log(`Typeshed path not found`);
1334
1328
  return undefined;
1335
1329
  }
1336
1330
  // Finds all of the stdlib modules and returns a Set containing all of their names.
@@ -1347,7 +1341,7 @@ class ImportResolver {
1347
1341
  const stripped = (0, pathUtils_1.stripFileExtension)(entry.name);
1348
1342
  // Skip anything starting with an underscore.
1349
1343
  if (!stripped.startsWith('_')) {
1350
- if (this._isStdlibTypeshedStubValidForVersion(createImportedModuleDescriptor(stripped), root, executionEnvironment.pythonVersion, executionEnvironment.pythonPlatform, [])) {
1344
+ if (this._isStdlibTypeshedStubValidForVersion(createImportedModuleDescriptor(stripped), root, executionEnvironment.pythonVersion, executionEnvironment.pythonPlatform)) {
1351
1345
  cache.add(prefix ? `${prefix}.${stripped}` : stripped);
1352
1346
  }
1353
1347
  }
@@ -1402,18 +1396,19 @@ class ImportResolver {
1402
1396
  this._cachedTypeshedThirdPartyPackageRoots = Array.from(new Set(flattenPaths)).sort();
1403
1397
  }
1404
1398
  _getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, isStdLib, suggestions) {
1405
- const importFailureInfo = [];
1406
1399
  let typeshedPaths;
1407
1400
  if (isStdLib) {
1408
- const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo, moduleDescriptor);
1401
+ const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform,
1402
+ /* importLogger */ undefined, moduleDescriptor);
1409
1403
  if (path) {
1410
1404
  typeshedPaths = [path];
1411
1405
  }
1412
1406
  }
1413
1407
  else {
1414
- typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo,
1408
+ typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor,
1409
+ /* importLogger */ undefined,
1415
1410
  /* includeMatchOnly */ false);
1416
- const typeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
1411
+ const typeshedPathEx = this.getTypeshedPathEx(execEnv);
1417
1412
  if (typeshedPathEx) {
1418
1413
  typeshedPaths = typeshedPaths ?? [];
1419
1414
  typeshedPaths.push(typeshedPathEx);
@@ -1431,21 +1426,21 @@ class ImportResolver {
1431
1426
  // Returns the directory for a module within the stdlib typeshed directory.
1432
1427
  // If moduleDescriptor is provided, it is filtered based on the VERSIONS
1433
1428
  // file in the typeshed stubs.
1434
- _getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo, moduleDescriptor) {
1435
- const subdirectory = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importFailureInfo);
1429
+ _getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform, importLogger, moduleDescriptor) {
1430
+ const subdirectory = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importLogger);
1436
1431
  if (subdirectory &&
1437
1432
  moduleDescriptor &&
1438
- !this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo)) {
1433
+ !this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importLogger)) {
1439
1434
  return undefined;
1440
1435
  }
1441
1436
  return subdirectory;
1442
1437
  }
1443
- _getThirdPartyTypeshedPath(customTypeshedPath, importFailureInfo) {
1444
- return this._getTypeshedSubdirectory(/* isStdLib */ false, customTypeshedPath, importFailureInfo);
1438
+ _getThirdPartyTypeshedPath(customTypeshedPath, importLogger) {
1439
+ return this._getTypeshedSubdirectory(/* isStdLib */ false, customTypeshedPath, importLogger);
1445
1440
  }
1446
- _isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo) {
1441
+ _isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importLogger) {
1447
1442
  if (!this._cachedTypeshedStdLibModuleVersionInfo) {
1448
- this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath, importFailureInfo);
1443
+ this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath, importLogger);
1449
1444
  }
1450
1445
  // Loop through the name parts to make sure the module and submodules
1451
1446
  // referenced in the import statement are valid for this version of Python.
@@ -1476,11 +1471,10 @@ class ImportResolver {
1476
1471
  }
1477
1472
  return true;
1478
1473
  }
1479
- _readTypeshedStdLibVersions(customTypeshedPath, importFailureInfo) {
1474
+ _readTypeshedStdLibVersions(customTypeshedPath, importLogger) {
1480
1475
  const versionRangeMap = new Map();
1481
1476
  // Read the VERSIONS file from typeshed.
1482
- const typeshedStdLibPath = this._getTypeshedSubdirectory(
1483
- /* isStdLib */ true, customTypeshedPath, importFailureInfo);
1477
+ const typeshedStdLibPath = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importLogger);
1484
1478
  if (typeshedStdLibPath) {
1485
1479
  const versionsFilePath = typeshedStdLibPath.combinePaths('VERSIONS');
1486
1480
  try {
@@ -1554,17 +1548,17 @@ class ImportResolver {
1554
1548
  });
1555
1549
  }
1556
1550
  else {
1557
- importFailureInfo.push(`Typeshed stdlib VERSIONS file is unexpectedly large`);
1551
+ importLogger?.log(`Typeshed stdlib VERSIONS file is unexpectedly large`);
1558
1552
  }
1559
1553
  }
1560
1554
  catch (e) {
1561
- importFailureInfo.push(`Could not read typeshed stdlib VERSIONS file: '${JSON.stringify(e)}'`);
1555
+ importLogger?.log(`Could not read typeshed stdlib VERSIONS file: '${JSON.stringify(e)}'`);
1562
1556
  }
1563
1557
  }
1564
1558
  return versionRangeMap;
1565
1559
  }
1566
- _getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo, includeMatchOnly = true) {
1567
- const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
1560
+ _getThirdPartyTypeshedPackagePaths(moduleDescriptor, importLogger, includeMatchOnly = true) {
1561
+ const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importLogger);
1568
1562
  if (!this._cachedTypeshedThirdPartyPackagePaths) {
1569
1563
  this._buildTypeshedThirdPartyPackageMap(typeshedPath);
1570
1564
  }
@@ -1577,14 +1571,14 @@ class ImportResolver {
1577
1571
  }
1578
1572
  return [];
1579
1573
  }
1580
- _getThirdPartyTypeshedPackageRoots(importFailureInfo) {
1581
- const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
1574
+ _getThirdPartyTypeshedPackageRoots(importLogger) {
1575
+ const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importLogger);
1582
1576
  if (!this._cachedTypeshedThirdPartyPackagePaths) {
1583
1577
  this._buildTypeshedThirdPartyPackageMap(typeshedPath);
1584
1578
  }
1585
1579
  return this._cachedTypeshedThirdPartyPackageRoots;
1586
1580
  }
1587
- _getTypeshedRoot(customTypeshedPath, importFailureInfo) {
1581
+ _getTypeshedRoot(customTypeshedPath, importLogger) {
1588
1582
  if (this._cachedTypeshedRoot === undefined) {
1589
1583
  let typeshedPath = undefined;
1590
1584
  // Did the user specify a typeshed path? If not, we'll look in the
@@ -1602,7 +1596,7 @@ class ImportResolver {
1602
1596
  }
1603
1597
  return this._cachedTypeshedRoot.isEmpty() ? undefined : this._cachedTypeshedRoot;
1604
1598
  }
1605
- _getTypeshedSubdirectory(isStdLib, customTypeshedPath, importFailureInfo) {
1599
+ _getTypeshedSubdirectory(isStdLib, customTypeshedPath, importLogger) {
1606
1600
  // See if we have it cached.
1607
1601
  if (isStdLib) {
1608
1602
  if (this._cachedTypeshedStdLibPath !== undefined) {
@@ -1614,7 +1608,7 @@ class ImportResolver {
1614
1608
  return this._cachedTypeshedThirdPartyPath;
1615
1609
  }
1616
1610
  }
1617
- let typeshedPath = this._getTypeshedRoot(customTypeshedPath, importFailureInfo);
1611
+ let typeshedPath = this._getTypeshedRoot(customTypeshedPath, importLogger);
1618
1612
  if (typeshedPath === undefined) {
1619
1613
  return undefined;
1620
1614
  }
@@ -1631,23 +1625,23 @@ class ImportResolver {
1631
1625
  }
1632
1626
  return typeshedPath;
1633
1627
  }
1634
- _resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo) {
1635
- importFailureInfo.push('Attempting to resolve relative import');
1628
+ _resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger) {
1629
+ importLogger?.log('Attempting to resolve relative import');
1636
1630
  // Determine which search path this file is part of.
1637
1631
  const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(sourceFileUri.getDirectory(), moduleDescriptor.leadingDots);
1638
1632
  if (!directory) {
1639
- importFailureInfo.push(`Invalid relative path '${importName}'`);
1633
+ importLogger?.log(`Invalid relative path '${importName}'`);
1640
1634
  return undefined;
1641
1635
  }
1642
1636
  // Now try to match the module parts from the current directory location.
1643
- const absImport = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
1637
+ const absImport = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importLogger,
1644
1638
  /* allowPartial */ false,
1645
1639
  /* allowNativeLib */ true);
1646
1640
  if (absImport && absImport.isStubFile) {
1647
1641
  // If we found a stub for a relative import, only search
1648
1642
  // the same folder for the real module. Otherwise, it will
1649
1643
  // error out on runtime.
1650
- absImport.nonStubImportResult = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
1644
+ absImport.nonStubImportResult = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importLogger,
1651
1645
  /* allowPartial */ false,
1652
1646
  /* allowNativeLib */ true,
1653
1647
  /* useStubPackage */ false,
@@ -1658,13 +1652,13 @@ class ImportResolver {
1658
1652
  isPartlyResolved: false,
1659
1653
  isNamespacePackage: false,
1660
1654
  isStubPackage: false,
1661
- importFailureInfo,
1655
+ importLogger,
1662
1656
  resolvedUris: [],
1663
1657
  importType: 2 /* ImportType.Local */,
1664
1658
  isStubFile: false,
1665
1659
  isNativeLib: false,
1666
- implicitImports: [],
1667
- filteredImplicitImports: [],
1660
+ implicitImports: undefined,
1661
+ filteredImplicitImports: undefined,
1668
1662
  nonStubImportResult: undefined,
1669
1663
  };
1670
1664
  }
@@ -1792,8 +1786,7 @@ class ImportResolver {
1792
1786
  let importResult;
1793
1787
  if (strictOnly) {
1794
1788
  const importName = formatImportName(moduleDescriptor);
1795
- const importFailureInfo = [];
1796
- importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
1789
+ importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor);
1797
1790
  }
1798
1791
  else {
1799
1792
  importResult = this.resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor);
@@ -1829,7 +1822,7 @@ class ImportResolver {
1829
1822
  }
1830
1823
  return (0, pyTypedUtils_1.getPyTypedInfoForPyTypedFile)(this.fileSystem, filePath.pytypedUri);
1831
1824
  }
1832
- _findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths) {
1825
+ _findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths) {
1833
1826
  let isNativeLib = false;
1834
1827
  if (!execEnv.skipNativeLibraries && this.dirExistsCached(fileDirectory)) {
1835
1828
  const filesInDir = this._getFilesInDirectory(fileDirectory);
@@ -1837,28 +1830,28 @@ class ImportResolver {
1837
1830
  const nativeLibPath = filesInDir.find((f) => this._isNativeModuleFileName(dirName, f));
1838
1831
  if (nativeLibPath) {
1839
1832
  // Try resolving native library to a custom stub.
1840
- isNativeLib = this._resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths);
1833
+ isNativeLib = this._resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths);
1841
1834
  if (isNativeLib) {
1842
- importFailureInfo.push(`Resolved with native lib '${nativeLibPath.toUserVisibleString()}'`);
1835
+ importLogger?.log(`Resolved with native lib '${nativeLibPath.toUserVisibleString()}'`);
1843
1836
  }
1844
1837
  }
1845
1838
  }
1846
1839
  return isNativeLib;
1847
1840
  }
1848
- _resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths) {
1841
+ _resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths) {
1849
1842
  let moduleFullName = importName;
1850
1843
  if (moduleDescriptor.leadingDots > 0) {
1851
1844
  // Relative path. Convert `.mtrand` to `numpy.random.mtrand` based on search path.
1852
1845
  const info = this.getModuleNameForImport(nativeLibPath, execEnv);
1853
1846
  moduleFullName = info.moduleName.length > 0 ? info.moduleName : moduleFullName;
1854
1847
  }
1855
- const compiledStubPath = this.resolveNativeImportEx(nativeLibPath, moduleFullName, importFailureInfo);
1848
+ const compiledStubPath = this.resolveNativeImportEx(nativeLibPath, moduleFullName, importLogger);
1856
1849
  if (compiledStubPath) {
1857
- importFailureInfo.push(`Resolved native import ${importName} with stub '${compiledStubPath}'`);
1850
+ importLogger?.log(`Resolved native import ${importName} with stub '${compiledStubPath}'`);
1858
1851
  resolvedPaths.push(compiledStubPath);
1859
1852
  return false; // Resolved to a stub.
1860
1853
  }
1861
- importFailureInfo.push(`Resolved import with file '${nativeLibPath}'`);
1854
+ importLogger?.log(`Resolved import with file '${nativeLibPath}'`);
1862
1855
  resolvedPaths.push(nativeLibPath);
1863
1856
  return true;
1864
1857
  }