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

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 (83) hide show
  1. package/dist/analyzer/binder.js +3 -3
  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/constraintTracker.d.ts +2 -2
  6. package/dist/analyzer/constraintTracker.js +5 -11
  7. package/dist/analyzer/constraintTracker.js.map +1 -1
  8. package/dist/analyzer/dataClasses.js +9 -2
  9. package/dist/analyzer/dataClasses.js.map +1 -1
  10. package/dist/analyzer/importLogger.d.ts +5 -0
  11. package/dist/analyzer/importLogger.js +24 -0
  12. package/dist/analyzer/importLogger.js.map +1 -0
  13. package/dist/analyzer/importResolver.d.ts +14 -7
  14. package/dist/analyzer/importResolver.js +188 -159
  15. package/dist/analyzer/importResolver.js.map +1 -1
  16. package/dist/analyzer/importResult.d.ts +2 -2
  17. package/dist/analyzer/importStatementUtils.js +6 -4
  18. package/dist/analyzer/importStatementUtils.js.map +1 -1
  19. package/dist/analyzer/operations.js +10 -1
  20. package/dist/analyzer/operations.js.map +1 -1
  21. package/dist/analyzer/program.js +18 -16
  22. package/dist/analyzer/program.js.map +1 -1
  23. package/dist/analyzer/protocols.js +11 -26
  24. package/dist/analyzer/protocols.js.map +1 -1
  25. package/dist/analyzer/pythonPathUtils.d.ts +2 -1
  26. package/dist/analyzer/pythonPathUtils.js +14 -14
  27. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  28. package/dist/analyzer/sentinel.js +3 -0
  29. package/dist/analyzer/sentinel.js.map +1 -1
  30. package/dist/analyzer/service.js +9 -10
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.js +14 -3
  33. package/dist/analyzer/sourceFile.js.map +1 -1
  34. package/dist/analyzer/typeEvaluator.js +33 -4
  35. package/dist/analyzer/typeEvaluator.js.map +1 -1
  36. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
  37. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  38. package/dist/analyzer/typeUtils.js +7 -1
  39. package/dist/analyzer/typeUtils.js.map +1 -1
  40. package/dist/analyzer/types.d.ts +1 -0
  41. package/dist/analyzer/types.js.map +1 -1
  42. package/dist/common/configOptions.js +4 -3
  43. package/dist/common/configOptions.js.map +1 -1
  44. package/dist/common/fullAccessHost.d.ts +5 -3
  45. package/dist/common/fullAccessHost.js +68 -19
  46. package/dist/common/fullAccessHost.js.map +1 -1
  47. package/dist/common/host.d.ts +11 -6
  48. package/dist/common/host.js +7 -4
  49. package/dist/common/host.js.map +1 -1
  50. package/dist/common/uri/memoization.js +19 -8
  51. package/dist/common/uri/memoization.js.map +1 -1
  52. package/dist/common/uri/uriUtils.d.ts +1 -1
  53. package/dist/common/uri/uriUtils.js +2 -1
  54. package/dist/common/uri/uriUtils.js.map +1 -1
  55. package/dist/common/uri/webUri.js +1 -1
  56. package/dist/common/uri/webUri.js.map +1 -1
  57. package/dist/languageService/completionProvider.js +1 -1
  58. package/dist/languageService/completionProvider.js.map +1 -1
  59. package/dist/localization/localize.d.ts +4 -0
  60. package/dist/localization/localize.js +2 -0
  61. package/dist/localization/localize.js.map +1 -1
  62. package/dist/localization/package.nls.en-us.json +5 -0
  63. package/dist/parser/parser.d.ts +1 -1
  64. package/dist/parser/parser.js +14 -3
  65. package/dist/parser/parser.js.map +1 -1
  66. package/dist/parser/tokenizer.js +12 -7
  67. package/dist/parser/tokenizer.js.map +1 -1
  68. package/dist/tests/harness/fourslash/testLanguageService.d.ts +1 -1
  69. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  70. package/dist/tests/harness/testAccessHost.d.ts +2 -1
  71. package/dist/tests/harness/testAccessHost.js +1 -1
  72. package/dist/tests/harness/testAccessHost.js.map +1 -1
  73. package/dist/tests/lsp/languageServerTestUtils.d.ts +4 -3
  74. package/dist/tests/lsp/languageServerTestUtils.js +3 -3
  75. package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
  76. package/dist/tests/parser.test.js +10 -0
  77. package/dist/tests/parser.test.js.map +1 -1
  78. package/dist/tests/typeEvaluator3.test.js +1 -1
  79. package/dist/tests/typeEvaluator5.test.js +1 -1
  80. package/dist/tests/typeEvaluator6.test.js +1 -5
  81. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  82. package/dist/tests/typeEvaluator7.test.js +1 -1
  83. 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) {
@@ -387,23 +383,35 @@ class ImportResolver {
387
383
  if (cachedValue) {
388
384
  return cachedValue;
389
385
  }
390
- let newCacheValue;
386
+ const newCachedDir = {
387
+ entries: new Map(),
388
+ resolvableNames: new Set(),
389
+ };
391
390
  try {
392
- newCacheValue = this.fileSystem.readdirEntriesSync(uri);
391
+ const entries = this.fileSystem.readdirEntriesSync(uri);
392
+ entries.forEach((entry) => {
393
+ newCachedDir.entries.set(entry.name, entry);
394
+ const resolvableName = entry.isFile()
395
+ ? (0, pathUtils_1.stripFileExtension)(entry.name, /* multiDotExtension */ true)
396
+ : entry.name;
397
+ newCachedDir.resolvableNames.add(resolvableName);
398
+ if (entry.isDirectory() && entry.name.endsWith(pathConsts_1.stubsSuffix)) {
399
+ newCachedDir.resolvableNames.add(resolvableName.substring(0, resolvableName.length - pathConsts_1.stubsSuffix.length));
400
+ }
401
+ });
393
402
  }
394
403
  catch {
395
- newCacheValue = [];
404
+ // Swallow error
396
405
  }
397
- // Populate cache for next time.
398
- this._cachedEntriesForPath.set(uri.key, newCacheValue);
399
- return newCacheValue;
406
+ // Populate cache.
407
+ this._cachedEntriesForPath.set(uri.key, newCachedDir);
408
+ return newCachedDir;
400
409
  }
401
410
  // Resolves the import and returns the path if it exists, otherwise
402
411
  // returns undefined.
403
412
  resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor) {
404
413
  const importName = formatImportName(moduleDescriptor);
405
- const importFailureInfo = [];
406
- const importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
414
+ const importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor);
407
415
  if (importResult.isImportFound || moduleDescriptor.leadingDots > 0) {
408
416
  return importResult;
409
417
  }
@@ -421,18 +429,19 @@ class ImportResolver {
421
429
  if (!this.cachedParentImportResults.checkValidPath(this.fileSystem, sourceFileUri, root)) {
422
430
  return importResult;
423
431
  }
424
- const localImportFailureInfo = [`Attempting to resolve using local imports: ${importName}`];
432
+ const importLogger = this._configOptions.verboseOutput ? new importLogger_1.ImportLogger() : undefined;
433
+ importLogger?.log(`Attempting to resolve using local imports: ${importName}`);
425
434
  const importPath = { importPath: undefined };
426
435
  // Going up the given folder one by one until we can resolve the import.
427
436
  let current = origin;
428
437
  while (this._shouldWalkUp(current, root, execEnv) && current) {
429
- const result = this.resolveAbsoluteImport(sourceFileUri, current, execEnv, moduleDescriptor, importName, localImportFailureInfo,
438
+ const result = this.resolveAbsoluteImport(sourceFileUri, current, execEnv, moduleDescriptor, importName, importLogger,
430
439
  /* allowPartial */ undefined,
431
440
  /* allowNativeLib */ undefined,
432
441
  /* useStubPackage */ false,
433
442
  /* allowPyi */ true);
434
443
  this.cachedParentImportResults.checked(current, importName, importPath);
435
- if (result.isImportFound) {
444
+ if (result?.isImportFound) {
436
445
  // This will make cache to point to actual path that contains the module we found
437
446
  importPath.importPath = current;
438
447
  this.cachedParentImportResults.add({
@@ -447,9 +456,9 @@ class ImportResolver {
447
456
  if (current) {
448
457
  this.cachedParentImportResults.checked(current, importName, importPath);
449
458
  }
450
- if (this._configOptions.verboseOutput) {
459
+ if (importLogger) {
451
460
  const console = this.serviceProvider.console();
452
- localImportFailureInfo.forEach((diag) => console.log(diag));
461
+ importLogger.getLogs().forEach((diag) => console.log(diag));
453
462
  }
454
463
  return importResult;
455
464
  }
@@ -459,9 +468,8 @@ class ImportResolver {
459
468
  // Started at root, so this can't be a file.
460
469
  return false;
461
470
  }
462
- const fileName = uri.fileName;
463
- const entries = this.readdirEntriesCached(directory);
464
- const entry = entries.find((entry) => entry.name === fileName);
471
+ const cachedDir = this.readdirEntriesCached(directory);
472
+ const entry = cachedDir.entries.get(uri.fileName);
465
473
  if (entry?.isFile()) {
466
474
  return true;
467
475
  }
@@ -487,9 +495,8 @@ class ImportResolver {
487
495
  }
488
496
  // Otherwise not a root, so read the entries we have cached to see if
489
497
  // the directory exists or not.
490
- const directoryName = uri.fileName;
491
- const entries = this.readdirEntriesCached(parent);
492
- const entry = entries.find((entry) => entry.name === directoryName);
498
+ const cachedDir = this.readdirEntriesCached(parent);
499
+ const entry = cachedDir.entries.get(uri.fileName);
493
500
  if (entry?.isDirectory()) {
494
501
  return true;
495
502
  }
@@ -509,12 +516,17 @@ class ImportResolver {
509
516
  }
510
517
  // Follows import resolution algorithm defined in PEP-420:
511
518
  // 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) {
519
+ resolveAbsoluteImport(sourceFileUri, rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial = false, allowNativeLib = false, useStubPackage = false, allowPyi = true, lookForPyTyped = false) {
520
+ // Before we do additional work, see if this directory can possibly
521
+ // resolve this import.
522
+ if (!this._isPossibleImportDir(rootPath, moduleDescriptor)) {
523
+ return undefined;
524
+ }
513
525
  if (allowPyi && useStubPackage) {
514
526
  // Look for packaged stubs first. PEP 561 indicates that package authors can ship
515
527
  // their stubs separately from their package implementation by appending the string
516
528
  // '-stubs' to its top - level directory name. We'll look there first.
517
- const importResult = this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial,
529
+ const importResult = this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial,
518
530
  /* allowNativeLib */ false,
519
531
  /* useStubPackage */ true,
520
532
  /* allowPyi */ true,
@@ -528,19 +540,19 @@ class ImportResolver {
528
540
  }
529
541
  }
530
542
  }
531
- return this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial, allowNativeLib,
543
+ return this._resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial, allowNativeLib,
532
544
  /* useStubPackage */ false, allowPyi, lookForPyTyped);
533
545
  }
534
546
  // Intended to be overridden by subclasses to provide additional stub
535
547
  // resolving capabilities. Return undefined if no stubs were found for
536
548
  // this import.
537
- resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo = [], allowPyi = true) {
549
+ resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger, allowPyi = true) {
538
550
  return undefined;
539
551
  }
540
552
  // Intended to be overridden by subclasses to provide additional stub
541
553
  // resolving capabilities for native (compiled) modules. Returns undefined
542
554
  // if no stubs were found for this import.
543
- resolveNativeImportEx(libraryFileUri, importName, importFailureInfo = []) {
555
+ resolveNativeImportEx(libraryFileUri, importName, importLogger) {
544
556
  return undefined;
545
557
  }
546
558
  getNativeModuleName(uri) {
@@ -555,13 +567,13 @@ class ImportResolver {
555
567
  filterImplicitImports(importResult, importedSymbols) {
556
568
  if (importedSymbols === undefined) {
557
569
  const newImportResult = Object.assign({}, importResult);
558
- newImportResult.filteredImplicitImports = new Map();
570
+ newImportResult.filteredImplicitImports = undefined;
559
571
  return newImportResult;
560
572
  }
561
- if (importedSymbols.size === 0) {
573
+ if (importedSymbols === undefined || importedSymbols.size === 0) {
562
574
  return importResult;
563
575
  }
564
- if (importResult.implicitImports.size === 0) {
576
+ if (importResult.implicitImports === undefined || importResult.implicitImports.size === 0) {
565
577
  return importResult;
566
578
  }
567
579
  const filteredImplicitImports = new Map();
@@ -580,7 +592,7 @@ class ImportResolver {
580
592
  findImplicitImports(importingModuleName, dirPath, exclusions) {
581
593
  const implicitImportMap = new Map();
582
594
  // Enumerate all of the files and directories in the path, expanding links.
583
- const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(dirPath), this.fileSystem, dirPath);
595
+ const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(dirPath).entries.values(), this.fileSystem, dirPath);
584
596
  // Add implicit file-based modules.
585
597
  for (const filePath of entries.files) {
586
598
  const fileExt = filePath.lastExtension;
@@ -612,7 +624,7 @@ class ImportResolver {
612
624
  // Try resolving resolving native lib to a custom stub.
613
625
  if (isNativeLib) {
614
626
  const nativeLibPath = filePath;
615
- const nativeStubPath = this.resolveNativeImportEx(nativeLibPath, `${importingModuleName}.${strippedFileName}`, []);
627
+ const nativeStubPath = this.resolveNativeImportEx(nativeLibPath, `${importingModuleName}.${strippedFileName}`);
616
628
  if (nativeStubPath) {
617
629
  implicitImport.uri = nativeStubPath;
618
630
  implicitImport.isNativeLib = false;
@@ -648,9 +660,26 @@ class ImportResolver {
648
660
  }
649
661
  }
650
662
  }
651
- return implicitImportMap;
663
+ return implicitImportMap.size > 0 ? implicitImportMap : undefined;
664
+ }
665
+ _isPossibleImportDir(rootPath, moduleDescriptor) {
666
+ const cachedDir = this.readdirEntriesCached(rootPath);
667
+ const isPotentialMatch = (name) => {
668
+ return cachedDir.resolvableNames.has(name);
669
+ };
670
+ if (moduleDescriptor.nameParts.length > 0) {
671
+ return isPotentialMatch(moduleDescriptor.nameParts[0]);
672
+ }
673
+ if (moduleDescriptor.importedSymbols) {
674
+ for (const key of moduleDescriptor.importedSymbols) {
675
+ if (isPotentialMatch(key)) {
676
+ return true;
677
+ }
678
+ }
679
+ }
680
+ return isPotentialMatch('__init__');
652
681
  }
653
- _resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo) {
682
+ _resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importLogger) {
654
683
  const fromUserFile = (0, configOptions_1.matchFileSpecs)(this._configOptions, sourceFileUri);
655
684
  const notFoundResult = {
656
685
  importName,
@@ -660,13 +689,13 @@ class ImportResolver {
660
689
  isNamespacePackage: false,
661
690
  isInitFilePresent: false,
662
691
  isStubPackage: false,
663
- importFailureInfo,
692
+ importFailureInfo: importLogger?.getLogs(),
664
693
  resolvedUris: [],
665
694
  importType: 2 /* ImportType.Local */,
666
695
  isStubFile: false,
667
696
  isNativeLib: false,
668
- implicitImports: new Map(),
669
- filteredImplicitImports: new Map(),
697
+ implicitImports: undefined,
698
+ filteredImplicitImports: undefined,
670
699
  nonStubImportResult: undefined,
671
700
  };
672
701
  this.ensurePartialStubPackages(execEnv);
@@ -676,7 +705,7 @@ class ImportResolver {
676
705
  if (cachedResults) {
677
706
  return cachedResults;
678
707
  }
679
- const relativeImport = this._resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo);
708
+ const relativeImport = this._resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger);
680
709
  if (relativeImport) {
681
710
  relativeImport.isRelative = true;
682
711
  return this.addResultsToCache(sourceFileUri, execEnv, importName, relativeImport, moduleDescriptor, fromUserFile);
@@ -712,7 +741,6 @@ class ImportResolver {
712
741
  /* moduleDescriptor */ undefined, fromUserFile);
713
742
  }
714
743
  _getCompletionSuggestionsStrict(sourceFileUri, execEnv, moduleDescriptor) {
715
- const importFailureInfo = [];
716
744
  const suggestions = new Map();
717
745
  // Is it a relative import?
718
746
  if (moduleDescriptor.leadingDots > 0) {
@@ -737,7 +765,7 @@ class ImportResolver {
737
765
  // Check for a typeshed file.
738
766
  this._getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, false, suggestions);
739
767
  // Look for the import in the list of third-party packages.
740
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
768
+ const pythonSearchPaths = this.getPythonSearchPaths();
741
769
  for (const searchPath of pythonSearchPaths) {
742
770
  this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, searchPath, moduleDescriptor, suggestions);
743
771
  }
@@ -750,14 +778,13 @@ class ImportResolver {
750
778
  let isLocalTypingsFile = false;
751
779
  let isThirdPartyPyTypedPresent = false;
752
780
  let isTypeshedFile = false;
753
- const importFailureInfo = [];
754
781
  // If we cannot find a fully-qualified module name with legal characters,
755
782
  // look for one with invalid characters (e.g. "-"). This is important to
756
783
  // differentiate between different modules in a project in case they
757
784
  // declare types with the same (local) name.
758
785
  let moduleNameWithInvalidCharacters;
759
786
  // Is this a stdlib typeshed path?
760
- const stdLibTypeshedPath = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo);
787
+ const stdLibTypeshedPath = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform);
761
788
  if (stdLibTypeshedPath) {
762
789
  moduleName = getModuleNameFromPath(stdLibTypeshedPath, fileUri);
763
790
  if (moduleName) {
@@ -766,7 +793,7 @@ class ImportResolver {
766
793
  nameParts: moduleName.split('.'),
767
794
  importedSymbols: undefined,
768
795
  };
769
- if (this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, [])) {
796
+ if (this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform)) {
770
797
  return {
771
798
  moduleName,
772
799
  importType,
@@ -828,7 +855,7 @@ class ImportResolver {
828
855
  }
829
856
  }
830
857
  // Check for a typeshed file.
831
- const thirdPartyTypeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
858
+ const thirdPartyTypeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath);
832
859
  if (thirdPartyTypeshedPath) {
833
860
  const candidateModuleName = getModuleNameFromPath(thirdPartyTypeshedPath, fileUri,
834
861
  /* stripTopContainerDir */ true);
@@ -840,7 +867,7 @@ class ImportResolver {
840
867
  isTypeshedFile = true;
841
868
  }
842
869
  }
843
- const thirdPartyTypeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
870
+ const thirdPartyTypeshedPathEx = this.getTypeshedPathEx(execEnv);
844
871
  if (thirdPartyTypeshedPathEx) {
845
872
  const candidateModuleName = getModuleNameFromPath(thirdPartyTypeshedPathEx, fileUri);
846
873
  // Does this candidate look better than the previous best module name?
@@ -852,7 +879,7 @@ class ImportResolver {
852
879
  }
853
880
  }
854
881
  // Look for the import in the list of third-party packages.
855
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
882
+ const pythonSearchPaths = this.getPythonSearchPaths();
856
883
  for (const searchPath of pythonSearchPaths) {
857
884
  const candidateModuleNameInfo = _getModuleNameInfoFromPath(searchPath, fileUri);
858
885
  if (candidateModuleNameInfo) {
@@ -912,12 +939,12 @@ class ImportResolver {
912
939
  this._cachedFilesForPath.clear();
913
940
  this._cachedDirExistenceForRoot.clear();
914
941
  }
915
- _resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial, allowNativeLib, useStubPackage, allowPyi, lookForPyTyped) {
942
+ _resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importLogger, allowPartial, allowNativeLib, useStubPackage, allowPyi, lookForPyTyped) {
916
943
  if (useStubPackage) {
917
- importFailureInfo.push(`Attempting to resolve stub package using root path '${rootPath}'`);
944
+ importLogger?.log(`Attempting to resolve stub package using root path '${rootPath}'`);
918
945
  }
919
946
  else {
920
- importFailureInfo.push(`Attempting to resolve using root path '${rootPath}'`);
947
+ importLogger?.log(`Attempting to resolve using root path '${rootPath}'`);
921
948
  }
922
949
  // Starting at the specified path, walk the file system to find the
923
950
  // specified module.
@@ -928,7 +955,7 @@ class ImportResolver {
928
955
  let isStubPackage = false;
929
956
  let isStubFile = false;
930
957
  let isNativeLib = false;
931
- let implicitImports = new Map();
958
+ let implicitImports;
932
959
  let packageDirectory;
933
960
  let pyTypedInfo;
934
961
  // Handle the "from . import XXX" case.
@@ -936,16 +963,16 @@ class ImportResolver {
936
963
  const pyFilePath = dirPath.initPyUri;
937
964
  const pyiFilePath = dirPath.initPyiUri;
938
965
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
939
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
966
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
940
967
  resolvedPaths.push(pyiFilePath);
941
968
  isStubFile = true;
942
969
  }
943
970
  else if (this.fileExistsCached(pyFilePath)) {
944
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
971
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
945
972
  resolvedPaths.push(pyFilePath);
946
973
  }
947
974
  else {
948
- importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
975
+ importLogger?.log(`Partially resolved import with directory '${dirPath}'`);
949
976
  resolvedPaths.push(uri_1.Uri.empty());
950
977
  isNamespacePackage = true;
951
978
  }
@@ -970,7 +997,7 @@ class ImportResolver {
970
997
  const pyiFilePath = dirPath.initPyiUri;
971
998
  isInitFilePresent = false;
972
999
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
973
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
1000
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
974
1001
  resolvedPaths.push(pyiFilePath);
975
1002
  if (isLastPart) {
976
1003
  isStubFile = true;
@@ -978,7 +1005,7 @@ class ImportResolver {
978
1005
  isInitFilePresent = true;
979
1006
  }
980
1007
  else if (this.fileExistsCached(pyFilePath)) {
981
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
1008
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
982
1009
  resolvedPaths.push(pyFilePath);
983
1010
  isInitFilePresent = true;
984
1011
  }
@@ -1005,20 +1032,20 @@ class ImportResolver {
1005
1032
  const pyiFilePath = dirPath.packageStubUri;
1006
1033
  const fileDirectory = dirPath.getDirectory();
1007
1034
  if (allowPyi && this.fileExistsCached(pyiFilePath)) {
1008
- importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
1035
+ importLogger?.log(`Resolved import with file '${pyiFilePath}'`);
1009
1036
  resolvedPaths.push(pyiFilePath);
1010
1037
  if (isLastPart) {
1011
1038
  isStubFile = true;
1012
1039
  }
1013
1040
  }
1014
1041
  else if (this.fileExistsCached(pyFilePath)) {
1015
- importFailureInfo.push(`Resolved import with file '${pyFilePath}'`);
1042
+ importLogger?.log(`Resolved import with file '${pyFilePath}'`);
1016
1043
  resolvedPaths.push(pyFilePath);
1017
1044
  }
1018
1045
  else if (allowNativeLib &&
1019
- this._findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths)) {
1046
+ this._findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths)) {
1020
1047
  isNativeLib = true;
1021
- importFailureInfo.push(`Did not find file '${pyiFilePath}' or '${pyFilePath}'`);
1048
+ importLogger?.log(`Did not find file '${pyiFilePath}' or '${pyFilePath}'`);
1022
1049
  }
1023
1050
  else if (foundDirectory) {
1024
1051
  if (!isLastPart) {
@@ -1030,7 +1057,7 @@ class ImportResolver {
1030
1057
  pyTypedInfo = undefined;
1031
1058
  continue;
1032
1059
  }
1033
- importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
1060
+ importLogger?.log(`Partially resolved import with directory '${dirPath}'`);
1034
1061
  resolvedPaths.push(uri_1.Uri.empty());
1035
1062
  if (isLastPart) {
1036
1063
  implicitImports = this.findImplicitImports(importName, dirPath, [pyFilePath, pyiFilePath]);
@@ -1059,7 +1086,7 @@ class ImportResolver {
1059
1086
  isStubPackage,
1060
1087
  isImportFound: importFound,
1061
1088
  isPartlyResolved,
1062
- importFailureInfo,
1089
+ importFailureInfo: importLogger?.getLogs(),
1063
1090
  importType: 2 /* ImportType.Local */,
1064
1091
  resolvedUris: resolvedPaths,
1065
1092
  searchPath: rootPath,
@@ -1094,27 +1121,27 @@ class ImportResolver {
1094
1121
  // are all satisfied by submodules (as listed in the implicit imports).
1095
1122
  _isNamespacePackageResolved(moduleDescriptor, implicitImports) {
1096
1123
  if (moduleDescriptor.importedSymbols) {
1097
- if (!Array.from(moduleDescriptor.importedSymbols.keys()).some((symbol) => implicitImports.has(symbol))) {
1124
+ if (!Array.from(moduleDescriptor.importedSymbols.keys()).some((symbol) => implicitImports?.has(symbol))) {
1098
1125
  return false;
1099
1126
  }
1100
1127
  }
1101
- else if (implicitImports.size === 0) {
1128
+ else if (!implicitImports || implicitImports.size === 0) {
1102
1129
  return false;
1103
1130
  }
1104
1131
  return true;
1105
1132
  }
1106
1133
  _resolveBestAbsoluteImport(sourceFileUri, execEnv, moduleDescriptor, allowPyi) {
1107
1134
  const importName = formatImportName(moduleDescriptor);
1108
- const importFailureInfo = [];
1135
+ const importLogger = this._configOptions.verboseOutput ? new importLogger_1.ImportLogger() : undefined;
1109
1136
  // Check for a local stub file using stubPath.
1110
1137
  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,
1138
+ importLogger?.log(`Looking in stubPath '${this._configOptions.stubPath}'`);
1139
+ const typingsImport = this.resolveAbsoluteImport(sourceFileUri, this._configOptions.stubPath, execEnv, moduleDescriptor, importName, importLogger,
1113
1140
  /* allowPartial */ undefined,
1114
1141
  /* allowNativeLib */ false,
1115
1142
  /* useStubPackage */ true, allowPyi,
1116
1143
  /* lookForPyTyped */ false);
1117
- if (typingsImport.isImportFound) {
1144
+ if (typingsImport?.isImportFound) {
1118
1145
  // We will treat typings files as "local" rather than "third party".
1119
1146
  typingsImport.importType = 2 /* ImportType.Local */;
1120
1147
  typingsImport.isLocalTypingsFile = true;
@@ -1136,8 +1163,8 @@ class ImportResolver {
1136
1163
  let localImport;
1137
1164
  // Look for it in the root directory of the execution environment.
1138
1165
  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,
1166
+ importLogger?.log(`Looking in root directory of execution environment ` + `'${execEnv.root}'`);
1167
+ localImport = this.resolveAbsoluteImport(sourceFileUri, execEnv.root, execEnv, moduleDescriptor, importName, importLogger,
1141
1168
  /* allowPartial */ undefined,
1142
1169
  /* allowNativeLib */ true,
1143
1170
  /* useStubPackage */ true, allowPyi,
@@ -1145,8 +1172,8 @@ class ImportResolver {
1145
1172
  bestResultSoFar = localImport;
1146
1173
  }
1147
1174
  for (const extraPath of execEnv.extraPaths) {
1148
- importFailureInfo.push(`Looking in extraPath '${extraPath}'`);
1149
- localImport = this.resolveAbsoluteImport(sourceFileUri, extraPath, execEnv, moduleDescriptor, importName, importFailureInfo,
1175
+ importLogger?.log(`Looking in extraPath '${extraPath}'`);
1176
+ localImport = this.resolveAbsoluteImport(sourceFileUri, extraPath, execEnv, moduleDescriptor, importName, importLogger,
1150
1177
  /* allowPartial */ undefined,
1151
1178
  /* allowNativeLib */ true,
1152
1179
  /* useStubPackage */ true, allowPyi,
@@ -1155,20 +1182,20 @@ class ImportResolver {
1155
1182
  }
1156
1183
  // Check for a stdlib typeshed file.
1157
1184
  if (allowPyi && moduleDescriptor.nameParts.length > 0) {
1158
- importFailureInfo.push(`Looking for typeshed stdlib path`);
1185
+ importLogger?.log(`Looking for typeshed stdlib path`);
1159
1186
  const typeshedStdlibImport = this._findTypeshedPath(execEnv, moduleDescriptor, importName,
1160
- /* isStdLib */ true, importFailureInfo);
1187
+ /* isStdLib */ true, importLogger);
1161
1188
  if (typeshedStdlibImport) {
1162
1189
  typeshedStdlibImport.isStdlibTypeshedFile = true;
1163
1190
  return typeshedStdlibImport;
1164
1191
  }
1165
1192
  }
1166
1193
  // Look for the import in the list of third-party packages.
1167
- const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
1194
+ const pythonSearchPaths = this.getPythonSearchPaths(importLogger);
1168
1195
  if (pythonSearchPaths.length > 0) {
1169
1196
  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,
1197
+ importLogger?.log(`Looking in python search path '${searchPath}'`);
1198
+ const thirdPartyImport = this.resolveAbsoluteImport(sourceFileUri, searchPath, execEnv, moduleDescriptor, importName, importLogger,
1172
1199
  /* allowPartial */ allowPartialResolutionForThirdPartyPackages,
1173
1200
  /* allowNativeLib */ true,
1174
1201
  /* useStubPackage */ true, allowPyi,
@@ -1180,26 +1207,26 @@ class ImportResolver {
1180
1207
  }
1181
1208
  }
1182
1209
  else {
1183
- importFailureInfo.push('No python interpreter search path');
1210
+ importLogger?.log('No python interpreter search path');
1184
1211
  }
1185
1212
  // If a library is fully py.typed, then we have found the best match,
1186
1213
  // unless the execution environment is typeshed itself, in which case
1187
1214
  // we don't want to favor py.typed libraries. Use the typeshed lookup below.
1188
- if (execEnv.root !== this._getTypeshedRoot(this._configOptions.typeshedPath, importFailureInfo)) {
1215
+ if (execEnv.root !== this._getTypeshedRoot(this._configOptions.typeshedPath, importLogger)) {
1189
1216
  if (bestResultSoFar?.pyTypedInfo && !bestResultSoFar.isPartlyResolved) {
1190
1217
  return bestResultSoFar;
1191
1218
  }
1192
1219
  }
1193
1220
  // Call the extensibility hook for subclasses.
1194
- const extraResults = this.resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo, allowPyi);
1221
+ const extraResults = this.resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger, allowPyi);
1195
1222
  if (extraResults) {
1196
1223
  return extraResults;
1197
1224
  }
1198
1225
  // Check for a third-party typeshed file.
1199
1226
  if (allowPyi && moduleDescriptor.nameParts.length > 0) {
1200
- importFailureInfo.push(`Looking for typeshed third-party path`);
1227
+ importLogger?.log(`Looking for typeshed third-party path`);
1201
1228
  const typeshedImport = this._findTypeshedPath(execEnv, moduleDescriptor, importName,
1202
- /* isStdLib */ false, importFailureInfo);
1229
+ /* isStdLib */ false, importLogger);
1203
1230
  if (typeshedImport) {
1204
1231
  typeshedImport.isThirdPartyTypeshedFile = true;
1205
1232
  bestResultSoFar = this._pickBestImport(bestResultSoFar, typeshedImport, moduleDescriptor);
@@ -1301,23 +1328,23 @@ class ImportResolver {
1301
1328
  }
1302
1329
  return bestImportSoFar;
1303
1330
  }
1304
- _findTypeshedPath(execEnv, moduleDescriptor, importName, isStdLib, importFailureInfo) {
1305
- importFailureInfo.push(`Looking for typeshed ${isStdLib ? PythonPathUtils.stdLibFolderName : PythonPathUtils.thirdPartyFolderName} path`);
1331
+ _findTypeshedPath(execEnv, moduleDescriptor, importName, isStdLib, importLogger) {
1332
+ importLogger?.log(`Looking for typeshed ${isStdLib ? PythonPathUtils.stdLibFolderName : PythonPathUtils.thirdPartyFolderName} path`);
1306
1333
  let typeshedPaths;
1307
1334
  if (isStdLib) {
1308
- const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo, moduleDescriptor);
1335
+ const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importLogger, moduleDescriptor);
1309
1336
  if (path) {
1310
1337
  typeshedPaths = [path];
1311
1338
  }
1312
1339
  }
1313
1340
  else {
1314
- typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo);
1341
+ typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importLogger);
1315
1342
  }
1316
1343
  if (typeshedPaths) {
1317
1344
  for (const typeshedPath of typeshedPaths) {
1318
1345
  if (this.dirExistsCached(typeshedPath)) {
1319
- const importInfo = this.resolveAbsoluteImport(undefined, typeshedPath, execEnv, moduleDescriptor, importName, importFailureInfo);
1320
- if (importInfo.isImportFound) {
1346
+ const importInfo = this.resolveAbsoluteImport(undefined, typeshedPath, execEnv, moduleDescriptor, importName, importLogger);
1347
+ if (importInfo?.isImportFound) {
1321
1348
  let importType = isStdLib ? 0 /* ImportType.BuiltIn */ : 1 /* ImportType.ThirdParty */;
1322
1349
  // Handle 'typing_extensions' as a special case because it's
1323
1350
  // part of stdlib typeshed stubs, but it's not part of stdlib.
@@ -1330,7 +1357,7 @@ class ImportResolver {
1330
1357
  }
1331
1358
  }
1332
1359
  }
1333
- importFailureInfo.push(`Typeshed path not found`);
1360
+ importLogger?.log(`Typeshed path not found`);
1334
1361
  return undefined;
1335
1362
  }
1336
1363
  // Finds all of the stdlib modules and returns a Set containing all of their names.
@@ -1338,7 +1365,7 @@ class ImportResolver {
1338
1365
  const cache = new Set();
1339
1366
  if (stdlibRoot) {
1340
1367
  const readDir = (root, prefix) => {
1341
- this.readdirEntriesCached(root).forEach((entry) => {
1368
+ this.readdirEntriesCached(root).entries.forEach((entry) => {
1342
1369
  if (entry.isDirectory()) {
1343
1370
  const dirRoot = root.combinePaths(entry.name);
1344
1371
  readDir(dirRoot, prefix ? `${prefix}.${entry.name}` : entry.name);
@@ -1347,7 +1374,7 @@ class ImportResolver {
1347
1374
  const stripped = (0, pathUtils_1.stripFileExtension)(entry.name);
1348
1375
  // Skip anything starting with an underscore.
1349
1376
  if (!stripped.startsWith('_')) {
1350
- if (this._isStdlibTypeshedStubValidForVersion(createImportedModuleDescriptor(stripped), root, executionEnvironment.pythonVersion, executionEnvironment.pythonPlatform, [])) {
1377
+ if (this._isStdlibTypeshedStubValidForVersion(createImportedModuleDescriptor(stripped), root, executionEnvironment.pythonVersion, executionEnvironment.pythonPlatform)) {
1351
1378
  cache.add(prefix ? `${prefix}.${stripped}` : stripped);
1352
1379
  }
1353
1380
  }
@@ -1366,10 +1393,10 @@ class ImportResolver {
1366
1393
  _buildTypeshedThirdPartyPackageMap(thirdPartyDir) {
1367
1394
  this._cachedTypeshedThirdPartyPackagePaths = new Map();
1368
1395
  if (thirdPartyDir) {
1369
- this.readdirEntriesCached(thirdPartyDir).forEach((outerEntry) => {
1396
+ this.readdirEntriesCached(thirdPartyDir).entries.forEach((outerEntry) => {
1370
1397
  if (outerEntry.isDirectory()) {
1371
1398
  const innerDirPath = thirdPartyDir.combinePaths(outerEntry.name);
1372
- this.readdirEntriesCached(innerDirPath).forEach((innerEntry) => {
1399
+ this.readdirEntriesCached(innerDirPath).entries.forEach((innerEntry) => {
1373
1400
  if (innerEntry.name === '@python2') {
1374
1401
  return;
1375
1402
  }
@@ -1402,18 +1429,19 @@ class ImportResolver {
1402
1429
  this._cachedTypeshedThirdPartyPackageRoots = Array.from(new Set(flattenPaths)).sort();
1403
1430
  }
1404
1431
  _getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, isStdLib, suggestions) {
1405
- const importFailureInfo = [];
1406
1432
  let typeshedPaths;
1407
1433
  if (isStdLib) {
1408
- const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform, importFailureInfo, moduleDescriptor);
1434
+ const path = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, execEnv.pythonPlatform,
1435
+ /* importLogger */ undefined, moduleDescriptor);
1409
1436
  if (path) {
1410
1437
  typeshedPaths = [path];
1411
1438
  }
1412
1439
  }
1413
1440
  else {
1414
- typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo,
1441
+ typeshedPaths = this._getThirdPartyTypeshedPackagePaths(moduleDescriptor,
1442
+ /* importLogger */ undefined,
1415
1443
  /* includeMatchOnly */ false);
1416
- const typeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
1444
+ const typeshedPathEx = this.getTypeshedPathEx(execEnv);
1417
1445
  if (typeshedPathEx) {
1418
1446
  typeshedPaths = typeshedPaths ?? [];
1419
1447
  typeshedPaths.push(typeshedPathEx);
@@ -1431,21 +1459,21 @@ class ImportResolver {
1431
1459
  // Returns the directory for a module within the stdlib typeshed directory.
1432
1460
  // If moduleDescriptor is provided, it is filtered based on the VERSIONS
1433
1461
  // file in the typeshed stubs.
1434
- _getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo, moduleDescriptor) {
1435
- const subdirectory = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importFailureInfo);
1462
+ _getStdlibTypeshedPath(customTypeshedPath, pythonVersion, pythonPlatform, importLogger, moduleDescriptor) {
1463
+ const subdirectory = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importLogger);
1436
1464
  if (subdirectory &&
1437
1465
  moduleDescriptor &&
1438
- !this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo)) {
1466
+ !this._isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importLogger)) {
1439
1467
  return undefined;
1440
1468
  }
1441
1469
  return subdirectory;
1442
1470
  }
1443
- _getThirdPartyTypeshedPath(customTypeshedPath, importFailureInfo) {
1444
- return this._getTypeshedSubdirectory(/* isStdLib */ false, customTypeshedPath, importFailureInfo);
1471
+ _getThirdPartyTypeshedPath(customTypeshedPath, importLogger) {
1472
+ return this._getTypeshedSubdirectory(/* isStdLib */ false, customTypeshedPath, importLogger);
1445
1473
  }
1446
- _isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importFailureInfo) {
1474
+ _isStdlibTypeshedStubValidForVersion(moduleDescriptor, customTypeshedPath, pythonVersion, pythonPlatform, importLogger) {
1447
1475
  if (!this._cachedTypeshedStdLibModuleVersionInfo) {
1448
- this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath, importFailureInfo);
1476
+ this._cachedTypeshedStdLibModuleVersionInfo = this._readTypeshedStdLibVersions(customTypeshedPath, importLogger);
1449
1477
  }
1450
1478
  // Loop through the name parts to make sure the module and submodules
1451
1479
  // referenced in the import statement are valid for this version of Python.
@@ -1476,11 +1504,10 @@ class ImportResolver {
1476
1504
  }
1477
1505
  return true;
1478
1506
  }
1479
- _readTypeshedStdLibVersions(customTypeshedPath, importFailureInfo) {
1507
+ _readTypeshedStdLibVersions(customTypeshedPath, importLogger) {
1480
1508
  const versionRangeMap = new Map();
1481
1509
  // Read the VERSIONS file from typeshed.
1482
- const typeshedStdLibPath = this._getTypeshedSubdirectory(
1483
- /* isStdLib */ true, customTypeshedPath, importFailureInfo);
1510
+ const typeshedStdLibPath = this._getTypeshedSubdirectory(/* isStdLib */ true, customTypeshedPath, importLogger);
1484
1511
  if (typeshedStdLibPath) {
1485
1512
  const versionsFilePath = typeshedStdLibPath.combinePaths('VERSIONS');
1486
1513
  try {
@@ -1554,17 +1581,17 @@ class ImportResolver {
1554
1581
  });
1555
1582
  }
1556
1583
  else {
1557
- importFailureInfo.push(`Typeshed stdlib VERSIONS file is unexpectedly large`);
1584
+ importLogger?.log(`Typeshed stdlib VERSIONS file is unexpectedly large`);
1558
1585
  }
1559
1586
  }
1560
1587
  catch (e) {
1561
- importFailureInfo.push(`Could not read typeshed stdlib VERSIONS file: '${JSON.stringify(e)}'`);
1588
+ importLogger?.log(`Could not read typeshed stdlib VERSIONS file: '${JSON.stringify(e)}'`);
1562
1589
  }
1563
1590
  }
1564
1591
  return versionRangeMap;
1565
1592
  }
1566
- _getThirdPartyTypeshedPackagePaths(moduleDescriptor, importFailureInfo, includeMatchOnly = true) {
1567
- const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
1593
+ _getThirdPartyTypeshedPackagePaths(moduleDescriptor, importLogger, includeMatchOnly = true) {
1594
+ const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importLogger);
1568
1595
  if (!this._cachedTypeshedThirdPartyPackagePaths) {
1569
1596
  this._buildTypeshedThirdPartyPackageMap(typeshedPath);
1570
1597
  }
@@ -1577,14 +1604,14 @@ class ImportResolver {
1577
1604
  }
1578
1605
  return [];
1579
1606
  }
1580
- _getThirdPartyTypeshedPackageRoots(importFailureInfo) {
1581
- const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
1607
+ _getThirdPartyTypeshedPackageRoots(importLogger) {
1608
+ const typeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importLogger);
1582
1609
  if (!this._cachedTypeshedThirdPartyPackagePaths) {
1583
1610
  this._buildTypeshedThirdPartyPackageMap(typeshedPath);
1584
1611
  }
1585
1612
  return this._cachedTypeshedThirdPartyPackageRoots;
1586
1613
  }
1587
- _getTypeshedRoot(customTypeshedPath, importFailureInfo) {
1614
+ _getTypeshedRoot(customTypeshedPath, importLogger) {
1588
1615
  if (this._cachedTypeshedRoot === undefined) {
1589
1616
  let typeshedPath = undefined;
1590
1617
  // Did the user specify a typeshed path? If not, we'll look in the
@@ -1602,7 +1629,7 @@ class ImportResolver {
1602
1629
  }
1603
1630
  return this._cachedTypeshedRoot.isEmpty() ? undefined : this._cachedTypeshedRoot;
1604
1631
  }
1605
- _getTypeshedSubdirectory(isStdLib, customTypeshedPath, importFailureInfo) {
1632
+ _getTypeshedSubdirectory(isStdLib, customTypeshedPath, importLogger) {
1606
1633
  // See if we have it cached.
1607
1634
  if (isStdLib) {
1608
1635
  if (this._cachedTypeshedStdLibPath !== undefined) {
@@ -1614,7 +1641,7 @@ class ImportResolver {
1614
1641
  return this._cachedTypeshedThirdPartyPath;
1615
1642
  }
1616
1643
  }
1617
- let typeshedPath = this._getTypeshedRoot(customTypeshedPath, importFailureInfo);
1644
+ let typeshedPath = this._getTypeshedRoot(customTypeshedPath, importLogger);
1618
1645
  if (typeshedPath === undefined) {
1619
1646
  return undefined;
1620
1647
  }
@@ -1631,40 +1658,40 @@ class ImportResolver {
1631
1658
  }
1632
1659
  return typeshedPath;
1633
1660
  }
1634
- _resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo) {
1635
- importFailureInfo.push('Attempting to resolve relative import');
1661
+ _resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importLogger) {
1662
+ importLogger?.log('Attempting to resolve relative import');
1636
1663
  // Determine which search path this file is part of.
1637
1664
  const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(sourceFileUri.getDirectory(), moduleDescriptor.leadingDots);
1638
1665
  if (!directory) {
1639
- importFailureInfo.push(`Invalid relative path '${importName}'`);
1666
+ importLogger?.log(`Invalid relative path '${importName}'`);
1640
1667
  return undefined;
1641
1668
  }
1642
1669
  // Now try to match the module parts from the current directory location.
1643
- const absImport = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
1670
+ const absImport = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importLogger,
1644
1671
  /* allowPartial */ false,
1645
1672
  /* allowNativeLib */ true);
1646
1673
  if (absImport && absImport.isStubFile) {
1647
1674
  // If we found a stub for a relative import, only search
1648
1675
  // the same folder for the real module. Otherwise, it will
1649
1676
  // error out on runtime.
1650
- absImport.nonStubImportResult = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
1677
+ absImport.nonStubImportResult = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importLogger,
1651
1678
  /* allowPartial */ false,
1652
1679
  /* allowNativeLib */ true,
1653
1680
  /* useStubPackage */ false,
1654
- /* allowPyi */ false) || {
1681
+ /* allowPyi */ false) ?? {
1655
1682
  importName,
1656
1683
  isRelative: true,
1657
1684
  isImportFound: false,
1658
1685
  isPartlyResolved: false,
1659
1686
  isNamespacePackage: false,
1660
1687
  isStubPackage: false,
1661
- importFailureInfo,
1688
+ isInitFilePresent: false,
1662
1689
  resolvedUris: [],
1663
1690
  importType: 2 /* ImportType.Local */,
1664
1691
  isStubFile: false,
1665
1692
  isNativeLib: false,
1666
- implicitImports: [],
1667
- filteredImplicitImports: [],
1693
+ implicitImports: undefined,
1694
+ filteredImplicitImports: undefined,
1668
1695
  nonStubImportResult: undefined,
1669
1696
  };
1670
1697
  }
@@ -1687,10 +1714,13 @@ class ImportResolver {
1687
1714
  let newCacheValue = [];
1688
1715
  try {
1689
1716
  const entriesInDir = this.readdirEntriesCached(dirPath);
1690
- const filesInDir = entriesInDir.filter((f) => f.isFile());
1691
- // Add any symbolic links that point to files.
1692
- entriesInDir.forEach((f) => {
1693
- if (f.isSymbolicLink() && (0, uriUtils_1.tryStat)(this.fileSystem, dirPath.combinePaths(f.name))?.isFile()) {
1717
+ const filesInDir = [];
1718
+ // Add any files or symbolic links that point to files.
1719
+ entriesInDir.entries.forEach((f) => {
1720
+ if (f.isFile()) {
1721
+ filesInDir.push(f);
1722
+ }
1723
+ else if (f.isSymbolicLink() && (0, uriUtils_1.tryStat)(this.fileSystem, dirPath.combinePaths(f.name))?.isFile()) {
1694
1724
  filesInDir.push(f);
1695
1725
  }
1696
1726
  });
@@ -1737,7 +1767,7 @@ class ImportResolver {
1737
1767
  }
1738
1768
  _addFilteredSuggestionsAbsolute(sourceFileUri, execEnv, currentPath, filter, suggestions, leadingDots, parentNameParts, strictOnly) {
1739
1769
  // Enumerate all of the files and directories in the path, expanding links.
1740
- const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(currentPath), this.fileSystem, currentPath);
1770
+ const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(currentPath).entries.values(), this.fileSystem, currentPath);
1741
1771
  entries.files.forEach((file) => {
1742
1772
  // Strip multi-dot extensions to handle file names like "foo.cpython-32m.so". We want
1743
1773
  // to detect the ".so" but strip off the entire ".cpython-32m.so" extension.
@@ -1792,8 +1822,7 @@ class ImportResolver {
1792
1822
  let importResult;
1793
1823
  if (strictOnly) {
1794
1824
  const importName = formatImportName(moduleDescriptor);
1795
- const importFailureInfo = [];
1796
- importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
1825
+ importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor);
1797
1826
  }
1798
1827
  else {
1799
1828
  importResult = this.resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor);
@@ -1829,7 +1858,7 @@ class ImportResolver {
1829
1858
  }
1830
1859
  return (0, pyTypedUtils_1.getPyTypedInfoForPyTypedFile)(this.fileSystem, filePath.pytypedUri);
1831
1860
  }
1832
- _findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths) {
1861
+ _findAndResolveNativeModule(fileDirectory, dirPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths) {
1833
1862
  let isNativeLib = false;
1834
1863
  if (!execEnv.skipNativeLibraries && this.dirExistsCached(fileDirectory)) {
1835
1864
  const filesInDir = this._getFilesInDirectory(fileDirectory);
@@ -1837,28 +1866,28 @@ class ImportResolver {
1837
1866
  const nativeLibPath = filesInDir.find((f) => this._isNativeModuleFileName(dirName, f));
1838
1867
  if (nativeLibPath) {
1839
1868
  // Try resolving native library to a custom stub.
1840
- isNativeLib = this._resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths);
1869
+ isNativeLib = this._resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths);
1841
1870
  if (isNativeLib) {
1842
- importFailureInfo.push(`Resolved with native lib '${nativeLibPath.toUserVisibleString()}'`);
1871
+ importLogger?.log(`Resolved with native lib '${nativeLibPath.toUserVisibleString()}'`);
1843
1872
  }
1844
1873
  }
1845
1874
  }
1846
1875
  return isNativeLib;
1847
1876
  }
1848
- _resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths) {
1877
+ _resolveNativeModuleWithStub(nativeLibPath, execEnv, importName, moduleDescriptor, importLogger, resolvedPaths) {
1849
1878
  let moduleFullName = importName;
1850
1879
  if (moduleDescriptor.leadingDots > 0) {
1851
1880
  // Relative path. Convert `.mtrand` to `numpy.random.mtrand` based on search path.
1852
1881
  const info = this.getModuleNameForImport(nativeLibPath, execEnv);
1853
1882
  moduleFullName = info.moduleName.length > 0 ? info.moduleName : moduleFullName;
1854
1883
  }
1855
- const compiledStubPath = this.resolveNativeImportEx(nativeLibPath, moduleFullName, importFailureInfo);
1884
+ const compiledStubPath = this.resolveNativeImportEx(nativeLibPath, moduleFullName, importLogger);
1856
1885
  if (compiledStubPath) {
1857
- importFailureInfo.push(`Resolved native import ${importName} with stub '${compiledStubPath}'`);
1886
+ importLogger?.log(`Resolved native import ${importName} with stub '${compiledStubPath}'`);
1858
1887
  resolvedPaths.push(compiledStubPath);
1859
1888
  return false; // Resolved to a stub.
1860
1889
  }
1861
- importFailureInfo.push(`Resolved import with file '${nativeLibPath}'`);
1890
+ importLogger?.log(`Resolved import with file '${nativeLibPath}'`);
1862
1891
  resolvedPaths.push(nativeLibPath);
1863
1892
  return true;
1864
1893
  }