A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-April/110572.html below:

[Python-Dev] abstractmethod doesn't work in classes

[Python-Dev] abstractmethod doesn't work in classes [Python-Dev] abstractmethod doesn't work in classesEugene Toder eltoder at gmail.com
Fri Apr 8 03:43:07 CEST 2011
Hello,

I've found that abstractmethod and similar decorators "don't work" in
classes, inherited from built-in types other than object.
For example:

>>> import abc
>>> class MyBase(metaclass=abc.ABCMeta):
	@abc.abstractmethod
	def foo(): pass

>>> MyBase()
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    MyBase()
TypeError: Can't instantiate abstract class MyBase with abstract methods foo

So far so good, but:

>>> class MyList(list, MyBase):
	pass

>>> MyList()
[]
>>> MyList.__abstractmethods__
frozenset({'foo'})

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.

Eugene
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4