Daniel Urban <urban.dani...@gmail.com> added the comment:

Thanks for the review!

I've updated my patch:
- renamed it to _PyType_CalculateMetaclass
- in __build_class__ call it even when a metaclass is declared
- added a test for this case (which fails with my previous patch)

However I noticed another problem: the declared metaclass (the object passed 
with the metaclass keyword in the class definition) according to PEP 3115 can 
be any callable object, not only a PyTypeObject. Problems:

1. In this case, PyType_IsSubtype will be called on something that is not a 
PyTypeObject (I don't know if that's a big problem, currently it seems to work).

2. The bigger problem: a simple construct, like:

class X(object, metaclass=func):
    pass

(where func is for example a function) won't work, because in 
_PyType_CalculateMetaclass it will detect, that func isn't a super- or subtype 
of object.__class__, and will raise an exception: "metaclass conflict: the 
metaclass of a derived class must be a (non-strict) subclass of the metaclasses 
of all its bases".

My first idea to solve this problem is to ignore this case in __build_class__ 
(check for a returned NULL, and call PyErr_Clear), and use the declared 
metaclass. (I don't know, if this can cause other problems, I haven't thought 
much about it yet.)

----------
Added file: http://bugs.python.org/file21729/issue_1294232_2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1294232>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to