[Python-ideas] mixins as decorators vs inheritance [was: Automatic comparisons by default]
Guido van Rossum
guido at python.org
Fri Mar 18 19:33:38 CET 2011
On Fri, Mar 18, 2011 at 10:21 AM, Masklinn <masklinn at masklinn.net> wrote:
> On 18 mars 2011, at 18:04, Raymond Hettinger <raymond.hettinger at gmail.com>
> 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
> 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.
That's debatable, and not the way the ABC debate for Python ended up.
And Java doesn't have the monopoly on the term interface.
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas