Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug that leads to a false positive error when --verifytypes i… #9569

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions packages/pyright-internal/src/analyzer/packageTypeVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import {
isDescriptorInstance,
isEllipsisType,
isPartlyUnknown,
partiallySpecializeType,
specializeForBaseClass,
} from './typeUtils';

type PublicSymbolSet = Set<string>;
Expand Down Expand Up @@ -510,7 +512,7 @@ export class PackageTypeVerifier {
symbolTable: SymbolTable,
scopeType: ScopeType,
publicSymbols: PublicSymbolSet,
overrideSymbolCallback?: (name: string, symbol: Symbol) => Symbol
overrideSymbolCallback?: (name: string, symbol: Symbol) => Type | undefined
): TypeKnownStatus {
if (this._shouldIgnoreType(report, scopeName)) {
return TypeKnownStatus.Known;
Expand Down Expand Up @@ -544,11 +546,10 @@ export class PackageTypeVerifier {
let childSymbolType: Type | undefined;

if (overrideSymbolCallback) {
const baseTypeSymbol = overrideSymbolCallback(name, symbol);
const baseSymbolType = overrideSymbolCallback(name, symbol);

if (baseTypeSymbol !== symbol) {
if (baseSymbolType) {
childSymbolType = symbolType;
baseSymbolType = this._program.getTypeOfSymbol(baseTypeSymbol);

// If the inferred type is ambiguous or the declared base class type is
// not the same type as the inferred type, mark it as ambiguous because
Expand Down Expand Up @@ -1164,18 +1165,23 @@ export class PackageTypeVerifier {
// If the symbol within this class is lacking a type declaration,
// see if we can find a same-named symbol in a parent class with
// a type declaration.
if (!symbol.hasTypedDeclarations()) {
for (const mroClass of type.shared.mro.slice(1)) {
if (isClass(mroClass)) {
const overrideSymbol = ClassType.getSymbolTable(mroClass).get(name);
if (overrideSymbol && overrideSymbol.hasTypedDeclarations()) {
return overrideSymbol;
}
if (symbol.hasTypedDeclarations()) {
return undefined;
}

for (const mroClass of type.shared.mro.slice(1)) {
if (isClass(mroClass)) {
const overrideSymbol = ClassType.getSymbolTable(mroClass).get(name);
if (overrideSymbol && overrideSymbol.hasTypedDeclarations()) {
const baseSymbolType = this._program.getTypeOfSymbol(overrideSymbol);
const baseClassType = specializeForBaseClass(type, mroClass);

return partiallySpecializeType(baseSymbolType, baseClassType, /* typeClass */ undefined);
}
}
}

return symbol;
return undefined;
}
);

Expand Down
Loading