[Python-3000] Abilities / Interfaces
Phillip J. Eby
pje at telecommunity.com
Wed Nov 22 18:12:16 CET 2006
At 11:41 AM 11/22/2006 -0500, Andrew Koenig wrote:
> > What does it add to have to declare a class as being "Iterable", if it
> > already implements __iter__? What does the notion of "Iterable" add to
> > the execution *or* understanding of the code?
>Let's suppose for the sake of argument that declaring a class as being
>"Iterable" adds nothing. What does that say about whether the ability to
>declare other abilities is useful? I think it doesn't say much.
I submit that every other ability can be similarly defined, because the
code to *implement* that ability must exist in one of three places:
1. a method of the object
2. a method of an adapter
3. a method registered somewhere, e.g. with a generic function
Neither #1 nor #3 require a separate interface declaration, and #2 can be
subsumed into an adaptation generic function -- which is actually what
iter() does, anyway.
Note that all three cases offer potential for directly verifying
implementation of the ability, whereas *declaring* an ability merely adds a
distinct *claim* that it has been implemented -- which then may need to be
More information about the Python-3000