[Python-3000] ABC's, Roles, etc
Phillip J. Eby
pje at telecommunity.com
Thu May 10 17:36:51 CEST 2007
At 09:06 AM 5/10/2007 -0400, Benji York wrote:
>I would let Jim speak for himself too, but I prefer to put words in his
>mouth. ;) While zope.interface has anemic facilities for "verifying"
>interfaces, few people use them, and even then rarely outside of very
>simple "does this object look right" when testing. It may have been
>believed verification would be a great thing, but it's all but
>deprecated at this point.
Okay, but that's quite the opposite of what I understand Jeff to be
saying in this thread, which is that not only is LBYL good, but that
he does it all the time.
>>And thus, for all of the use cases you just described, the minimal
>>PEP 3124 Interface implementation should do just fine, yes?
>
>Could be, especially if it allows for adaptation.
Yes, it does. In fact, adaptation is pretty much all they're good
for, except for specifying argument types:
http://python.org/dev/peps/pep-3124/#interfaces-and-adaptation
http://python.org/dev/peps/pep-3124/#interfaces-as-type-specifiers
>My main intent in piping up was
>dispelling the LBYL dispersions about zope.interface. ;)
Well, "back in the day", before PyProtocols was written, I discovered
PEP 246 adaptation and began trying to convince Jim Fulton that
adaptation beat the pants off of using if-then's to do "implements"
testing. His argument then, IIRC, was that interface verification
was more important. I then went off and wrote PyProtocols in large
part (specifically the large documentation part!) to show him what
could be done using adaptation as a core concept.
>If the PEP cooperates as well with zope.interface as you suggest, all
>will be good in the world. Personally I'd prefer sufficient hooks be
>added to the language and these types of things (interfaces, adaptation,
>generic functions, etc.) be left to third parties (like yourself)
>instead of being canonicalized unnecessarily.
Well, as Nick Coghlan's already pointed out, the PEP is mostly about
creating a standard set of hooks, so that each framework doesn't have
to reinvent decorators and syntax.
>>Indeed, ABCs would work for those use cases too, if you didn't need
>>adaptation. Or am I missing something?
>
>The main advantage I see to zope.interface is adaptation. Other
>than that, the fact that the inheritance and interface hierarchies
>aren't mixed.
In which case, you might well be happy with PEP 3124 interfaces,
unless you want to use instance-specific interfaces a lot.
>I would turn the argument around and assert that interfaces can be used
>for the rare LBYL uses that ABCs appear to be aimed at, as well as more
>interesting things.
Sure, which is another reason why PEP 3124 includes them.
More information about the Python-3000
mailing list