This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author douglas-raillard-arm
Recipients douglas-raillard-arm
Date 2022-03-28.14:32:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648477925.18.0.27195455918.issue47144@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-03-28 14:32:05douglas-raillard-armsetrecipients: + douglas-raillard-arm
2022-03-28 14:32:05douglas-raillard-armsetmessageid: <1648477925.18.0.27195455918.issue47144@roundup.psfhosted.org>
2022-03-28 14:32:05douglas-raillard-armlinkissue47144 messages
2022-03-28 14:32:05douglas-raillard-armcreate