'isa' keyword

Terry Hancock hancock at anansispaceworks.com
Wed Sep 7 11:16:57 EDT 2005


On Sunday 04 September 2005 07:25 am, Colin J. Williams wrote:
> Rocco Moretti wrote:
> > Terry Hancock wrote:
> > 
> >> On Thursday 01 September 2005 07:28 am, Fuzzyman wrote:
> >>
> >>> What's the difference between this and ``isinstance`` ?
> >>
> >>
> >> I must confess that an "isa" operator sounds like it would
> >> have been slightly nicer syntax than the isinstance() built-in
> >> function. But not enough nicer to change, IMHO.
> > 
> > 
> > Especially conidering that checking parameters with "isinstance" is 
> > considered bad form with Python's duck typing.
> 
> Could you elaborate on that please?

It would indeed be better to have a keyword for querying whether
a class or object *implements* a given *interface*.  Which is essentially
what "duck typing" does, albeit somewhat haphazardly.  The formal
alternative, of using interfaces is provided by external packages
such as Zope and PyProtocols, but has never been standardized and
adopted into the standard library.  Perhaps it should be.

Certainly as long as there is more than one implementation of
interfaces, support for testing them cannot be at the keyword
level and remains through functions and methods.  This is actually
pretty easy to use, though.

Giving isinstance() a keyword status as "isa" would encourage
bad style, though, as it would attract beginners away from much
better styles such as component/interface design.

While that wouldn't necessarily be sufficient reason to *remove*
an "isa" keyword if one existed, it certainly detracts from the
desire to add one.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list