[Python-ideas] Name mangling and code repetition (with cooperative inheritance use case)

Shane Green shane at umbrellacode.com
Tue Apr 9 09:16:45 CEST 2013


"""Cooperative inheritance is however also a great pick for such a use case. In
this type of implementation if a subclass cannot do the job (render), it will
delegate the work with super() to the next class in the mro chain. The usage
of `__private` is justified here, since each subclass in the chain has to
ensure that some of the used methods are his own internal methods:"""

This isn't normally what name mangling is used for; it's used to hide private properties so they cannot be accessed, and are basically invisible, outside the context of that class definition.  Methods can be accessed as a property of the class anytime their origin need to be restricted.



Sent from my iPad

On Apr 8, 2013, at 6:54 PM, Zahari Petkov <zarchaoz at gmail.com> wrote:

> 
> Cooperative inheritance is however also a great pick for such a use case. In
> this type of implementation if a subclass cannot do the job (render), it will
> delegate the work with super() to the next class in the mro chain. The usage
> of `__private` is justified here, since each subclass in the chain has to
> ensure that some of the used methods are his own internal methods:



More information about the Python-ideas mailing list