[Python-ideas] mixins as decorators vs inheritance [was: Automatic comparisons by default]

Masklinn masklinn at masklinn.net
Fri Mar 18 17:29:59 CET 2011


On 2011-03-18, at 13:59 , Jim Jewett wrote:

> On Thu, Mar 17, 2011 at 9:48 AM, Mike Graham <mikegraham at gmail.com> wrote:
>> On Wed, Mar 16, 2011 at 5:48 PM, Masklinn <masklinn at masklinn.net> wrote:
>>> (also, since I apparently completely missed this,
>>> what was the rationale of making it a class
>>> decorator rather than, say, a mixin?)
> 
>> Perhaps the better question is "Why do we ever
>> do mixins through inheritance?"
> 
> That is a good question, and I was tempted to switch,
> until I realized that there are some good answers...
> 
> (a)  So we can do an isinstance check
> (b)  So we can more easily override parts of the mixin

(c) Class decorators are harder to get into and implement (an inherited mixin is mostly an inheritable class, a class decorator skirts much closer to metatypes play)
(d) Class decorators are a recent feature and manually decorating class was never something widely used (as opposed to decorating functions)
(e) plain old inertia


More information about the Python-ideas mailing list