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

Masklinn masklinn at masklinn.net
Fri Mar 18 18:21:39 CET 2011


On 18 mars 2011, at 18:04, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> On Mar 18, 2011, at 6:58 AM, Mike Graham wrote:
>> 
>> (a) is a misfeature. isinstance checks are bad: they make your code
>> less flexible – in Python the actual type of an object isn't something
>> we treat as semantic data. This is *especially* the case with mixins,
>> which are just a convenient thing for code reuse, not some meaningful
>> type.
> 
> I believe that is outdated advice.  Since Guido introduced 
> abstract base classes, the trend (and grain) of Python is to
> use isinstance() to check for a given interface (i.e. distinguishing
> a Sequence from a Mapping)
I'm not sure "interface" is the best word here as it probably has java-inherited links to explicit, static specification, whereas a (good) abc instance check would, I believe, check the shape of the testee instead. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110318/30f2d421/attachment.html>


More information about the Python-ideas mailing list