Confused about pep 318
Skip Montanaro
skip at pobox.com
Wed Aug 4 18:22:48 EDT 2004
Edward> But I have no idea what the proposed syntax is(!!) In
Edward> particular, there is no mention of '@' directly on the page
Edward> http://www.python.org/peps/pep-0318.html
Anthony Baxter said yesterday on python-dev he was going to attend to that
shortly. As in many other software efforts, the code has moved along a bit
faster than the documentation (after all, what's more fun to do?). I
believe the only significant differences from a pure functional
documentation standpoint to apply to the PEP are the syntax and the issue of
decorated classes (I don't think support for decorated classes will make
it). By way of parallel examples here's how the new syntax corresponds to
the syntax I used in the last revision of the PEP:
#1 from the PEP: Given this function:
def onexit(f):
import atexit
atexit.register(f)
return f
the new syntax will be:
@onexit
def func():
...
#4 from the PEP: Given these functions:
def accepts(*types):
def check_accepts(f):
assert len(types) == f.func_code.co_argcount
def new_f(*args, **kwds):
for (a, t) in zip(args, types):
assert isinstance(a, t), \
"arg %r does not match %s" % (a,t)
return f(*args, **kwds)
return new_f
return check_accepts
def returns(rtype):
def check_returns(f):
def new_f(*args, **kwds):
result = f(*args, **kwds)
assert isinstance(result, rtype), \
"return value %r does not match %s" % (result,rtype)
return result
return new_f
return check_returns
the new syntax will be:
@accepts(int, (int,float))
@returns((int,float))
def func(arg1, arg2):
return arg1 * arg2
I believe the order of application of the above decorators would be like so:
func = accepts(int, (int, float))(returns((int, float))(func)
Edward> I confess that I don't understand this remark at all. How has
Edward> it happened that so many people are confused about this
Edward> proposal? And if everything is so clear, why isn't the clarity
Edward> reflected in pep 318 itself?
There was a lot of discussion on python-dev, but none very recently (last
month or so). Guido indicated there that he brought up the topic at
EuroPython in his keynote talk and entertained discussion from the floor.
Based upon that discussion he decided to go with the @-decorator syntax.
Since EuroPython most/all the discussion went on in private email or on
irc. I think it would be nice if this conversation was summarized in the
PEP, but that will have to come from one of the participants.
Skip
More information about the Python-list
mailing list