PEP 318 - Function Modifier Syntax
jepler at unpythonic.net
Wed Jun 11 15:06:02 CEST 2003
On Tue, Jun 10, 2003 at 02:57:24PM -0700, Erik Max Francis wrote:
> Jonathan Claggett wrote:
> > How about overloading the keyword "is" instead of "as"? As far as
> > English readability is concerned, this might be clearer. "Is" also
> > fits in well with established OO terminology (e.g., a square is a
> > rhombus, a function is a static method).
> Deja vu. The benefit, as I see it, is that `as' is a secondary keyword
> -- it presently only has meaning in conjunction with an 'import'
> statement. Since it's a lowly little preposition, it doesn't have all
> that much intrinsic meaning by itself. If adding keywords were "free,"
> perhaps some new word might be helpful, such as `has'. But there is
> significant inertia against adding new keywords, so if we can make do
> with old ones, so much the better. I personally think that `as' is a
> very good choice for this because of its secondary nature.
> The problem with using `is' is that it already has a very specific
> meaning, namely in the use of the `is' operator.
Can I jump on the "re-use an existing reserved word where it doesn't
def f() for staticmethod:
def f() finally staticmethod:
def f() del staticmethod:
def f() import staticmethod:
def f() class staticmethod:
oh, you don't like any of those? Sorry!
Actually, I think that just like 'import ... as' a word could be chosen
to go after the function arguments that is not a reserved word. The
grammar would read
funcdef: 'def' NAME parameters (NAME testlist)?
and the second NAME would be required to be the word chosen for the
function modifier, if it's present. This leads to ideas like
def f() with modifiers withlock(l), classmethod
(here it would be (NAME NAME testlist, since 'with modifiers' is two
All that said, I'm +1 on the 'def f() [modifiers]' syntax and at best
+0 on other syntaxes. In general I'm -1 on any syntax that puts the
modifiers before the parameter list. I'd like to see some variation of
318 implemented, though.
More information about the Python-list