[Python-Dev] abstractmethod doesn't work in classes
eltoder at gmail.com
Fri Apr 8 03:43:07 CEST 2011
I've found that abstractmethod and similar decorators "don't work" in
classes, inherited from built-in types other than object.
>>> import abc
>>> class MyBase(metaclass=abc.ABCMeta):
def foo(): pass
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
TypeError: Can't instantiate abstract class MyBase with abstract methods foo
So far so good, but:
>>> class MyList(list, MyBase):
This is unexpected, since MyList still doesn't implement foo.
Should this be considered a bug? I don't see this in documentation.
The underlying reason is that __abstractmethods__ is checked in
object_new, but built-in types typically call tp_alloc directly, thus
skipping the check.
More information about the Python-Dev