Added logic to better handle the case where a symbol is defined multiple times with a TypeAlias declaration. This is an error condition, but it does occur in some stdlib type stubs if pyright is configured to use "All" for the "pythonPlatform" setting.

This commit is contained in:
Eric Traut 2022-05-29 02:03:50 -07:00
parent ee8f7c21d6
commit 006541d053

View File

@ -18684,9 +18684,18 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
});
}
let sawExplicitTypeAlias = false;
decls.forEach((decl, index) => {
let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
// If we have already seen an explicit type alias, do not consider
// additional decls. This can happen if multiple TypeAlias declarations
// are provided -- normally an error, but it can happen in stdlib stubs
// if the user sets the pythonPlatform to "All".
if (sawExplicitTypeAlias) {
considerDecl = false;
}
if (usageNode !== undefined) {
if (decl.type !== DeclarationType.Alias) {
// Is the declaration in the same execution scope as the "usageNode" node?
@ -18704,6 +18713,10 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(decl);
const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasDeclaration(decl);
if (isExplicitTypeAlias) {
sawExplicitTypeAlias = true;
}
// If this is a type alias, evaluate it outside of the recursive symbol
// resolution check so we can evaluate the full assignment statement.
if (