Changed the import resolution order to better reflect runtime behavior and match a proposed change to the typing spec. In particular, stdlib typeshed stubs are now resolved prior to site_packages. This addresses #8099. (#8100)

This commit is contained in:
Eric Traut 2024-06-09 07:57:44 -07:00 committed by GitHub
parent e588c6f984
commit 45fcebfe2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1634,6 +1634,23 @@ export class ImportResolver {
bestResultSoFar = this._pickBestImport(bestResultSoFar, localImport, moduleDescriptor);
}
// Check for a stdlib typeshed file.
if (allowPyi && moduleDescriptor.nameParts.length > 0) {
importFailureInfo.push(`Looking for typeshed stdlib path`);
const typeshedStdlibImport = this._findTypeshedPath(
execEnv,
moduleDescriptor,
importName,
/* isStdLib */ true,
importFailureInfo
);
if (typeshedStdlibImport) {
typeshedStdlibImport.isStdlibTypeshedFile = true;
return typeshedStdlibImport;
}
}
// Look for the import in the list of third-party packages.
const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
if (pythonSearchPaths.length > 0) {
@ -1687,23 +1704,8 @@ export class ImportResolver {
return extraResults;
}
// Check for a third-party typeshed file.
if (allowPyi && moduleDescriptor.nameParts.length > 0) {
// Check for a stdlib typeshed file.
importFailureInfo.push(`Looking for typeshed stdlib path`);
const typeshedStdlibImport = this._findTypeshedPath(
execEnv,
moduleDescriptor,
importName,
/* isStdLib */ true,
importFailureInfo
);
if (typeshedStdlibImport) {
typeshedStdlibImport.isStdlibTypeshedFile = true;
return typeshedStdlibImport;
}
// Check for a third-party typeshed file.
importFailureInfo.push(`Looking for typeshed third-party path`);
const typeshedImport = this._findTypeshedPath(
execEnv,