Improved completions for class member access when the member variable in a child class is unannotated but a parent class provides an annotation. In this case, we should use the type information from the annotated symbol.

This commit is contained in:
Eric Traut 2022-02-11 09:54:16 -08:00
parent 713c9f1c01
commit 2090c5f09b

View File

@ -1587,7 +1587,13 @@ export function getMembersForClass(classType: ClassType, symbolTable: SymbolTabl
if (symbol.isClassMember() || (includeInstanceVars && symbol.isInstanceMember())) {
if (!isClassTypedDict || !isTypedDictMemberAccessedThroughIndex(symbol)) {
if (!symbol.isInitVar()) {
if (!symbolTable.get(name)) {
const existingSymbol = symbolTable.get(name);
if (!existingSymbol) {
symbolTable.set(name, symbol);
} else if (!existingSymbol.hasTypedDeclarations() && symbol.hasTypedDeclarations()) {
// If the existing symbol is unannotated but a parent class
// has an annotation for the symbol, use the parent type instead.
symbolTable.set(name, symbol);
}
}
@ -1604,7 +1610,13 @@ export function getMembersForClass(classType: ClassType, symbolTable: SymbolTabl
for (const mroClass of metaclass.details.mro) {
if (isInstantiableClass(mroClass)) {
mroClass.details.fields.forEach((symbol, name) => {
if (!symbolTable.get(name)) {
const existingSymbol = symbolTable.get(name);
if (!existingSymbol) {
symbolTable.set(name, symbol);
} else if (!existingSymbol.hasTypedDeclarations() && symbol.hasTypedDeclarations()) {
// If the existing symbol is unannotated but a parent class
// has an annotation for the symbol, use the parent type instead.
symbolTable.set(name, symbol);
}
});