Skip to content

Commit 1ec90d1

Browse files
committed
Changed logic to exempt abstract overloaded methods within an ABC so an implementation is not required. This is related to mypy issue python/mypy#11488.
1 parent 4474b7d commit 1ec90d1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/pyright-internal/src/analyzer/checker.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -2845,18 +2845,30 @@ export class Checker extends ParseTreeWalker {
28452845
}
28462846

28472847
if (!implementationFunction) {
2848-
let isProtocolMethod = false;
2848+
let exemptMissingImplementation = false;
2849+
28492850
const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(primaryDecl.node);
28502851
if (containingClassNode && containingClassNode.nodeType === ParseNodeType.Class) {
28512852
const classType = this._evaluator.getTypeOfClass(containingClassNode);
2852-
if (classType && ClassType.isProtocolClass(classType.classType)) {
2853-
isProtocolMethod = true;
2853+
if (classType) {
2854+
if (ClassType.isProtocolClass(classType.classType)) {
2855+
exemptMissingImplementation = true;
2856+
} else if (ClassType.supportsAbstractMethods(classType.classType)) {
2857+
if (
2858+
isOverloadedFunction(type) &&
2859+
OverloadedFunctionType.getOverloads(type).every((overload) =>
2860+
FunctionType.isAbstractMethod(overload)
2861+
)
2862+
) {
2863+
exemptMissingImplementation = true;
2864+
}
2865+
}
28542866
}
28552867
}
28562868

28572869
// If this is a method within a protocol class, don't require that
28582870
// there is an implementation.
2859-
if (!isProtocolMethod) {
2871+
if (!exemptMissingImplementation) {
28602872
this._evaluator.addDiagnostic(
28612873
this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
28622874
DiagnosticRule.reportGeneralTypeIssues,

0 commit comments

Comments
 (0)