[Python-ideas] generic Liftable abc-mixin breaks at MRO
Stephan Sahm
Stephan.Sahm at gmx.de
Thu Dec 10 04:35:50 EST 2015
thanks for the fast response
in fact, I do use this already, however more generically:
def lift(self, new_class, **kwargs):
...
self.__class__ = new_class
...
On 10 December 2015 at 10:33, M.-A. Lemburg <mal at egenix.com> wrote:
> 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/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151210/3ceb05c9/attachment-0001.html>
More information about the Python-ideas
mailing list