Skip to content

Commit

Permalink
Changed logic to exempt abstract overloaded methods within an ABC so …
Browse files Browse the repository at this point in the history
…an implementation is not required. This is related to mypy issue python/mypy#11488.
  • Loading branch information
msfterictraut committed Aug 25, 2023
1 parent 4474b7d commit 1ec90d1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2845,18 +2845,30 @@ export class Checker extends ParseTreeWalker {
}

if (!implementationFunction) {
let isProtocolMethod = false;
let exemptMissingImplementation = false;

const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(primaryDecl.node);
if (containingClassNode && containingClassNode.nodeType === ParseNodeType.Class) {
const classType = this._evaluator.getTypeOfClass(containingClassNode);
if (classType && ClassType.isProtocolClass(classType.classType)) {
isProtocolMethod = true;
if (classType) {
if (ClassType.isProtocolClass(classType.classType)) {
exemptMissingImplementation = true;
} else if (ClassType.supportsAbstractMethods(classType.classType)) {
if (
isOverloadedFunction(type) &&
OverloadedFunctionType.getOverloads(type).every((overload) =>
FunctionType.isAbstractMethod(overload)
)
) {
exemptMissingImplementation = true;
}
}
}
}

// If this is a method within a protocol class, don't require that
// there is an implementation.
if (!isProtocolMethod) {
if (!exemptMissingImplementation) {
this._evaluator.addDiagnostic(
this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
DiagnosticRule.reportGeneralTypeIssues,
Expand Down

0 comments on commit 1ec90d1

Please sign in to comment.