Use typeshed version info for stdlib module list (#7982)

This commit is contained in:
Ujan RoyBandyopadhyay 2024-05-23 11:04:55 -05:00 committed by GitHub
parent 50d4f44735
commit bfc60526a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -338,7 +338,7 @@ export class ImportResolver {
isStdlibModule(module: ImportedModuleDescriptor, execEnv: ExecutionEnvironment): boolean {
if (!this._stdlibModules) {
this._stdlibModules = this._buildStdlibCache(this.getTypeshedStdLibPath(execEnv));
this._stdlibModules = this._buildStdlibCache(this.getTypeshedStdLibPath(execEnv), execEnv);
}
return this._stdlibModules.has(module.nameParts.join('.'));
@ -1895,7 +1895,7 @@ export class ImportResolver {
}
// Finds all of the stdlib modules and returns a Set containing all of their names.
private _buildStdlibCache(stdlibRoot: Uri | undefined): Set<string> {
private _buildStdlibCache(stdlibRoot: Uri | undefined, executionEnvironment: ExecutionEnvironment): Set<string> {
const cache = new Set<string>();
if (stdlibRoot) {
@ -1908,7 +1908,17 @@ export class ImportResolver {
const stripped = stripFileExtension(entry.name);
// Skip anything starting with an underscore.
if (!stripped.startsWith('_')) {
cache.add(prefix ? `${prefix}.${stripped}` : stripped);
if (
this._isStdlibTypeshedStubValidForVersion(
createImportedModuleDescriptor(stripped),
root,
executionEnvironment.pythonVersion,
executionEnvironment.pythonPlatform,
[]
)
) {
cache.add(prefix ? `${prefix}.${stripped}` : stripped);
}
}
}
});