PEP 318 - Function Modifier Syntax
Michele Simionato
mis6 at pitt.edu
Tue Jun 10 12:02:15 EDT 2003
Kevin Smith <Kevin.Smith at sas.com> wrote in message news:<20030609081617512-0400 at braeburn.themorgue.org>...
> This is the first draft of a PEP describing new syntax for applying
> function modifiers (e.g. classmethod, staticmethod, etc). There is
> currently no implementation of the proposed syntax (I have heard rumors
> that the 'def foo(self) [...]' syntax has a patch somewhere, but I
> haven't seen it yet). I have already received a few comments and will
> revise the document soon. The latest version will always be available
> at http://www.python.org/peps/pep-0318.html.
>
>
> Function Modifier Syntax
> ------------------------
I proposed some type ago to extend the notation for classes. For instance
class C(A,B)[Traced,Syncronized]: pass
would mean
class C(A,B): __metaclass__=type("TracedSyncronized",(Traced,Syncronized),{})
For functions instead the interpretation would be
def f(x,y)[traced,syncronized]: pass
meaning (as in the current PEP)
def f(x,y): pass
f=traced(syncronized(f))
It is not perfect, since the interpretation of the syntax would differ
for functions and classes, but who cares? "practicality beats purity" ;)
Originally I wanted an "is" sugar
class C(A,B) is Traced,Syncronized:
pass
def f(x,y) is traced,syncronized:
pass
which looks better but people protested that "is" has another
meaning. Another possibility (suggested by Bengt Richter) would
be
class C(A,B) becomes Traced,Syncronized:
pass
def f(x,y) becomes traced,syncronized:
pass
Michele
More information about the Python-list
mailing list