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

VA report at bugs.python.org
Tue Feb 6 03:13:25 EST 2018


VA <d.python.dc54 at indigo.re> added the comment:

The use case is a little more complex.

I have a plugin system, with abstract interfaces. Plugins can't import each other, but plugins should be able to allowed to depend on another plugin (using string codes, still no direct imports), and even subclass another plugin's classes (and override some of their methods).

In the sample code, A and C would be 2 plugins, and B would be a helper class (with string code parameters) whose purpose is to make a temporary bridge between A and C.
A should work standalone. C would use A's code but could reimplement some of A's methods. B is a internal class that has A and C at hand, and changes C's __bases__ to point to A.

I have been suggested other solutions, like using composition (a C instance would have an "a" field pointing to an A instance) to avoid inheritance altogether, or using the "type()" function in B.__new__ to create a custom class inheriting A.
None of these solutions are really satisfying because they prevent C from using "super(...)" to refer to A methods.
Rebinding __class__ simply does not allow to override methods at all.

----------

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


More information about the Python-bugs-list mailing list