PEP 245: Python interfaces

Dave LeBlanc whisper at oz.net
Mon Mar 26 15:40:36 EST 2001


Having read the PEP briefly, I have one question:

Is there a good reason to add the "implements" keyword?

Current syntax is (from Language Reference 7.6):
classdef:       "class" classname [inheritance] ":" suite
inheritance:    "(" [expression_list] ")"
classname:      identifier
(i'm adding this based on the text of 7.6:)
expression_list: Expression(s) which evaluate to a class object.

Any reason why expression_list couldn't include an interface? Seems to
me it's easier to just extend the semantics of expression_list to
include interface_name(s) instead of adding a variation like '"class"
classname [inheritance] ["implements"   interfaces] ":" suite'.
(Besides, two optional elements in a row makes for messy parsing :-).)
The end of a class definition might be slightly more complex to check
that all "pure" methods have implementations, but (almost certianly)
not hopelessly so... and you get to detect the "not implemented" error
early with a "missing definition" error rather then later with a
"can't instantiate" error.

Surely a python interpreter could be smart enough to realize that some
name in the list of inherited objects is actually an interface?
(OTOH, it doesn't seem smart enough to infer that the first argument
of a method within a class is "self" <g>).

Of course, one could do '"class" classname [" inherits" inheritance]
["implements" interfaces] ":" suite'  if verbosity is the goal. (This
would also be easier to parse :-).)

Just my $.02 worth.

Dave LeBlanc

On Thu, 22 Mar 2001 23:02:35 -0800, Michel Pelletier
<michel at digicool.com> wrote:

>
>Hi!
>
>I'm the author of PEP 245, a framework and syntax for interface objects in
>Python.
>
>http://python.sourceforge.net/peps/pep-0245.html
>
>It has just recently been made a PEP, and I'd like to solicite some more
>input from the community (you).
>
>For those of you who don't know the formal defintion of "interface", don't
>worry (there isn't one!).  There are, however, a lot of agreed and
>disagreed upon definitions out there in the world, and PEP 245 is one
>particular take on the situation, based on pioneering work done by the
>Type-sig and Jim Fulton over the last couple of years.
>
>There is a Wiki (referenced in the PEP) for formal discussion and, of
>course, this newsgroup, which I will hanging out in for the next few days
>answering any questions about the proposal.
>
>Thanks!
>
>-Michel
>




More information about the Python-list mailing list