mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
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:
parent
713c9f1c01
commit
2090c5f09b
@ -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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user