Message266684
> why write `metatype == &PyType_Type` rather than
> PyType_CheckExact(metatype)`?
If only `type` should implement this special case, then it needs to be `metatype == &PyType_Type`. This was actually how it was implemented in 2.2a3:
https://hg.python.org/cpython/file/v2.2a3/Objects/typeobject.c#l631
I don't know why the final release of 2.2 switched to using PyType_CheckExact, which is true for most metaclasses. That's why I feel like I'm missing something here.
Probably it used PyType_CheckExact instead of PyType_Check to ensure PyType_IsSubtype wouldn't be called. Nowadays that's optimized away via PyType_FastSubclass and the Py_TPFLAGS_TYPE_SUBCLASS flag (set up in inherit_special). If it's decided to retain this special case for metaclasses other than `type`, then I think it should use PyType_Check to consistently implement it for all metaclasses. Also, the error message should be more generic, e.g. maybe "__new__() takes 1 or 3 arguments". |
|
Date |
User |
Action |
Args |
2016-05-30 08:08:57 | eryksun | set | recipients:
+ eryksun, gvanrossum, rhettinger, steven.daprano, r.david.murray, ppperry, abarry |
2016-05-30 08:08:57 | eryksun | set | messageid: <1464595737.85.0.701957815861.issue27157@psf.upfronthosting.co.za> |
2016-05-30 08:08:57 | eryksun | link | issue27157 messages |
2016-05-30 08:08:57 | eryksun | create | |
|