[Python-ideas] mixins as decorators vs inheritance [was: Automatic comparisons by default]
Guido van Rossum
guido at python.org
Fri Mar 18 17:24:02 CET 2011
On Fri, Mar 18, 2011 at 8:39 AM, Jack Diederich <jackdied at gmail.com> wrote:
> On Fri, Mar 18, 2011 at 8:59 AM, Jim Jewett <jimjjewett at gmail.com> 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
> total_ordering won't override methods you've explicitly written. And
> IMO mixins were always a work-around and not a feature. Class
> decorators are a cleaner way of doing a similar thing.
There are some cases where class decorators are better than mixins,
but I don't think we should start rejecting the mixin class pattern
outright. The two patterns work differently and have different
strengths. Inheritance may be overrated, but it isn't dead!
(Also, ABCs give new life to certain isinstance checks. isinstance
isn't dead yet either. :-)
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas