Issue 9533: metaclass can't derive from ABC (original) (raw)

Created on 2010-08-06 10:33 by roalddevries, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)

msg113094 - (view)

Author: Roald de Vries (roalddevries)

Date: 2010-08-06 10:33

Exception raised::

Traceback (most recent call last): File "bug.py", line 5, in class derived(type, Sized): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/abc.py", line 85, in new for name in getattr(base, "abstractmethods", set()): TypeError: Error when calling the metaclass bases 'getset_descriptor' object is not iterable

msg114025 - (view)

Author: Terry J. Reedy (terry.reedy) * (Python committer)

Date: 2010-08-15 23:22

+- same traceback in 3.1 Since ABCmeta is not used (by name) its import is not needed. I have no opinion on whether this should work.

msg117802 - (view)

Author: Daniel Urban (daniel.urban) * (Python triager)

Date: 2010-10-01 14:10

If we create a new class, which is a metaclass, and also inherits an ABC, we create a new instance of ABCMeta.

When ABCMeta.new creates the abstractmethods attribute of the new class, it iterates over the abstractmethods attribute of every base class (and checks every name in it, if it's abstract in the new class). One of the base classes of a metaclass is of course type. The type.abstractmethods object is a getset descriptor (its set switches some flags in tp_flags), which isn't iterable, so it raises the exception.

Ideas for possible solutions:

  1. In ABCMeta.new special case type (do not check its __abstractmethods__attribute).
  2. In ABCMeta.new check if the abstractmethods attribute is in fact an iterable, before we try to iterate over it. (I don't think this would be a very good solution, because if a base class' abstractmethods isn't iterable, it should be an error, except if the base class is type itself. So we should special case type anyway.)

I can't come up with a use case for this right now, but I don't see why it shouldn't work.

msg117880 - (view)

Author: R. David Murray (r.david.murray) * (Python committer)

Date: 2010-10-02 14:18

Does the "fix" for issue 10006 affect this? (I imagine that question is why Antoine made Benjamin nosy on this issue).

msg117891 - (view)

Author: Benjamin Peterson (benjamin.peterson) * (Python committer)

Date: 2010-10-02 17:53

You can now create metaclass abcs. However, having abstractmethods does not prevent instance creation. This is a problem with a builtins, though.

History

Date

User

Action

Args

2022-04-11 14:57:05

admin

set

github: 53742

2010-10-02 17:53:46

benjamin.peterson

set

status: open -> closed
resolution: fixed
messages: +

2010-10-02 14🔞09

r.david.murray

set

nosy: + r.david.murray
messages: +

2010-10-02 12:23:01

pitrou

set

nosy: + benjamin.peterson

2010-10-01 14:10:04

daniel.urban

set

nosy:terry.reedy, eric.araujo, daniel.urban, roalddevries
messages: +
components: + Library (Lib)

2010-09-20 22:59:29

eric.araujo

set

nosy: + eric.araujo

2010-08-15 23:22:51

terry.reedy

set

nosy: + terry.reedy

messages: +
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6

2010-08-06 16:07:36

daniel.urban

set

nosy: + daniel.urban
type: compile error -> behavior

2010-08-06 10:33:37

roalddevries

create