[Python-ideas] generic Liftable abc-mixin breaks at MRO

M.-A. Lemburg mal at egenix.com
Thu Dec 10 04:33:09 EST 2015


On 10.12.2015 09:58, Stephan Sahm wrote:
> Dear all,
> 
> I think I found a crucial usecase where the standard MRO does not work out.
> I would appreciate your help to still solve this usecase, or might MRO even
> be adapted?
> 
> The idea is to build a generic Lift-type which I call this way because the
> derived classes should be able to easily lift from subclasses. So for
> example if I have an instance *a* from *class A* and a *class B(A)* I want
> to make *a* an instance of *B* in a straightforward way.

Why don't you use:

a.__class__ = B

?

>>> class A: pass
...
>>> class B(A): pass
...
>>> a = A()
>>> a
<__main__.A instance at 0x7f0bf5ccdc68>
>>> a.__class__ = B
>>> a
<__main__.B instance at 0x7f0bf5ccdc68>
>>>

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Dec 10 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Python-ideas mailing list