Message134097
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.) |
|
Date |
User |
Action |
Args |
2011-04-19 20:43:31 | daniel.urban | set | recipients:
+ daniel.urban, gvanrossum, georg.brandl, terry.reedy, amaury.forgeotdarc, ncoghlan, rodsenra, pwerneck, benjamin.peterson |
2011-04-19 20:43:31 | daniel.urban | set | messageid: <1303245811.02.0.750959202745.issue1294232@psf.upfronthosting.co.za> |
2011-04-19 20:43:30 | daniel.urban | link | issue1294232 messages |
2011-04-19 20:43:30 | daniel.urban | create | |
|