Eryk Sun added the comment:

> 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".

----------

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

Reply via email to