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

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


On 10.12.2015 10:35, Stephan Sahm wrote:
> 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
>     ...

Hmm, then I don't understand why you need a meta class
for this. Could you explain the requirements that led up to
needing a meta class ?

If all you want to do is let the lift() know about
a certain property of a class to do it's thing, an
attribute or perhaps an empty base class would do the
trick, e.g.

class A:
    __liftable__ = True

or perhaps:

class A:
    def lift(self, ...):
        # lift operation goes here

> 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/
>>
>>
> 
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 

-- 
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