Message416172
The cell object __classcell__ currently cannot be set by code invoked by metaclass.__new__. Attempts to do so will be caught by builtin___build_class__ in bltimodule.c:
} else {
const char *msg =
"__class__ set to %.200R defining %.200R as %.200R";
PyErr_Format(PyExc_TypeError, msg, cell_cls, name, cls);
}
This is unfortunate as there is a use-case for such trickery: if the method of a class A are only used to be grafted onto another class B (monkey patching), A.__classcell__ should be set to B so that super() works as expected.
This can be useful in contexts where e.g. A.__new__ returns instances of B. B is not necessarily something under direct user control (it can be dynamically created by inheriting from a "template"), so A would be a better place for users to define custom method. |
|
Date |
User |
Action |
Args |
2022-03-28 14:32:05 | douglas-raillard-arm | set | recipients:
+ douglas-raillard-arm |
2022-03-28 14:32:05 | douglas-raillard-arm | set | messageid: <1648477925.18.0.27195455918.issue47144@roundup.psfhosted.org> |
2022-03-28 14:32:05 | douglas-raillard-arm | link | issue47144 messages |
2022-03-28 14:32:05 | douglas-raillard-arm | create | |
|