Message266651
In Objects/typeobject.c#L2290, the code checks that the (meta?)class is exactly `type` and that there's one argument, then returns `Py_TYPE(x)`. Subclasses of `type` allowing a single argument is a side-effect of not overriding __new__, not a documented feature.
Changing the call from `PyType_CheckExact` to `PyType_Check` makes it work, but I'm assuming there may be something I didn't think of. Or maybe there isn't, but either way, I don't consider that this is worth fixing -- if you want to call your subclass with only one argument, override __new__ and do the logic in there. And if you want the type of an object, use type directly.
Also, there may be performance concerns here. `type` is heavily optimized in many places; I thought that `PyType_Check` called Python code, but after checking the macro definitions and testing a bit, it turns out I'm wrong. But if there *is* a negative performance impact, this probably can't go in -- this check runs everytime that type() is called, no matter how many arguments, and including in class creation; that's also probably why `PyType_CheckExact` was chosen to begin with. |
|
Date |
User |
Action |
Args |
2016-05-30 00:12:08 | abarry | set | recipients:
+ abarry, ppperry |
2016-05-30 00:12:08 | abarry | set | messageid: <1464567128.92.0.837750760047.issue27157@psf.upfronthosting.co.za> |
2016-05-30 00:12:08 | abarry | link | issue27157 messages |
2016-05-30 00:12:08 | abarry | create | |
|