[issue32768] object.__new__ does not accept arguments if __bases__ is changed

Nick Coghlan report at bugs.python.org
Wed Feb 7 02:39:42 EST 2018


Nick Coghlan <ncoghlan at gmail.com> added the comment:

>From VA's description of the intended use case, this actually sounds a bit like a variant of https://bugs.python.org/issue29944: one reason that replacing C with a new dynamically constructed type won't work reliably is because some of the methods might have captured references to the original type via closure cells, so zero-arg super() will still fail, even if you rebind the name at the module level.

Even __set_name__ can't reliably help with that, since it would rely on every descriptor passing on the __set_name__ call to wrapped objects.

While the problem likely isn't fixable for the class-cloning case, we may be able to do something about the class-replacement case by exposing the zero-arg super() class cell as an attribute on the class object.

If we did that, then methods on the original class could be pointed at the new class by doing "original_class.__classcell__.cell_contents = new_class".

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32768>
_______________________________________


More information about the Python-bugs-list mailing list