mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
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:
parent
e588c6f984
commit
45fcebfe2c
@ -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;
|
||||
}
|
||||
|
||||
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.
|
||||
if (allowPyi && moduleDescriptor.nameParts.length > 0) {
|
||||
importFailureInfo.push(`Looking for typeshed third-party path`);
|
||||
const typeshedImport = this._findTypeshedPath(
|
||||
execEnv,
|
||||
|
Loading…
Reference in New Issue
Block a user