[New-bugs-announce] [issue43010] @functools.wraps and abc.abstractmethod interoperability

Erez Zinman report at bugs.python.org
Sat Jan 23 09:26:11 EST 2021

New submission from Erez Zinman <erezinman.programmer at gmail.com>:

Consider the following code:

from abc import ABC, abstractmethod
from functools import wraps

class A(ABC):
    def f(self):
    def wrapper(self):
        print('f is called!')
class B(A):
    def f(self):


The last line of code results in the following error:
>>> TypeError: Can't instantiate abstract class B with abstract methods wrapper

That happens because `wraps` copies the `__dict__` of the original function. The problem is that at the point of declaration, the `__dict__` also contained `__isabstractmethod__=True` so it was copied as well, and it caused an error on the class' instantiation even though it contained no abstract methods. 
Moreover, this behavior is misleading because the the wrapper function is not abstract. 


components: Extension Modules, Library (Lib)
messages: 385538
nosy: erezinman
priority: normal
severity: normal
status: open
title: @functools.wraps and abc.abstractmethod interoperability
type: behavior
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list