Message311731
I fear that this is one of those cases that will longer in the tracker
forever. We probably shouldn't have allowed assignment to __bases__, and
the behavior is slightly surprising, but fixing it would be too complicated
and there's not enough interest in getting it fixed.
On Feb 6, 2018 12:13 AM, "VA" <report@bugs.python.org> wrote:
>
> VA <d.python.dc54@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@bugs.python.org>
> <https://bugs.python.org/issue32768>
> _______________________________________
> |
|
| Date |
User |
Action |
Args |
| 2018-02-06 16:41:57 | gvanrossum | set | recipients:
+ gvanrossum, ncoghlan, r.david.murray, serhiy.storchaka, VA |
| 2018-02-06 16:41:57 | gvanrossum | link | issue32768 messages |
| 2018-02-06 16:41:57 | gvanrossum | create | |
|