Fixed a bug that caused incorrect type evaluation because of stale module paths that are cached for specific source files. Module paths are dependent on the list of configured import resolution paths, so when the import resolution paths change, we may need to recompute the module path for a source file.

This commit is contained in:
Eric Traut 2022-08-03 11:12:12 -07:00
parent 05c46fc09a
commit cdba65d4c8
2 changed files with 14 additions and 2 deletions

View File

@ -262,12 +262,16 @@ export class Program {
addTrackedFile(filePath: string, isThirdPartyImport = false, isInPyTypedPackage = false): SourceFile {
let sourceFileInfo = this._getSourceFileInfoFromPath(filePath);
const importName = this._getImportNameForFile(filePath);
if (sourceFileInfo) {
// The module name may have changed based on updates to the
// search paths, so update it here.
sourceFileInfo.sourceFile.setModuleName(importName);
sourceFileInfo.isTracked = true;
return sourceFileInfo.sourceFile;
}
const importName = this._getImportNameForFile(filePath);
const sourceFile = new SourceFile(
this._fs,
filePath,

View File

@ -97,7 +97,7 @@ export class SourceFile {
private readonly _filePath: string;
// Period-delimited import path for the module.
private readonly _moduleName: string;
private _moduleName: string;
// True if file is a type-hint (.pyi) file versus a python
// (.py) file.
@ -247,6 +247,14 @@ export class SourceFile {
return this._filePath;
}
getModuleName(): string {
return this._moduleName;
}
setModuleName(name: string) {
this._moduleName = name;
}
getDiagnosticVersion(): number {
return this._diagnosticVersion;
}