470,591 Members | 2,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

PEP-318, billion-and-first syntax proposal

As soon as one of these syntax discussions go on long enough, I start to
think that, whatever the problem ,it should be solved by thunks (search
python dev if you need to know what a thunk is) or something thunk-like.
It's a personal weakness, I suppose. In that vein, here's my entry into
the Great Decorator Debate 2004.


BLOCK is executed in a separate namespace *before* EXPRESSION is
evaluated. EXPRESSION is then evaluated in BLOCK's namespace. This is
probably best illustrated with an example or three:

class C:

# The standard staticmethod example. It works reasonably well
for this, but is
# a bit wordier than some examples. It's clear what's happening

def foo as staticmethod(body):
def body(x, y):

# This method generalized nicely to properties, which I like.

def bar as property(getbar, setbar, None, doc):
doc = "That crazy bar property!"
def getbar(self):
def setbar(self, value):

# It's pretty good for the nasty long decorators and arg list case.

def bar as OBJCDecorator("@#%$@#^",
SomeOtherDecorator("asdfasf", body)):
def body(a_long_argument_list, with_long_arg_name, _etc.):

This syntax is by no means perfect; it's a little wordy in the simple
case for one thing. But it's more obvious what's happening in this
syntax than in any of the others that I've seen which I think is a big

It also generalizes well to the hypothetical Python 3000 with optional
type checking, since the signature can be placed on the user visible
'foo' instead of on the pre-transform body:

def foo(int, int)->int as staticmethod(body):
def body(x, y):



Jul 18 '05 #1
0 906

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

59 posts views Thread by Raymond Hettinger | last post: by
72 posts views Thread by Raymond Hettinger | last post: by
20 posts views Thread by Micah Elliott | last post: by
77 posts views Thread by Ben Finney | last post: by
399 posts views Thread by =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.