[Python-Dev] Pep 318 - new syntax for wrappers
Bob Ippolito
bob at redivi.com
Wed Mar 3 13:55:08 EST 2004
On Mar 3, 2004, at 10:20 AM, Jewett, Jim J wrote:
> I think everyone agrees that decorators are useful, and the
> current idiom is awkward; the only real argument is over how
> to improve it. Proponents want something easy to type; others
> want something explicit.
>
>
> (1) Eventually, there will be another good idea.
>
> Therefore, we should define a general extension syntax,
> rather than a special case for this particular extension.
>
> def func(args) [wrapper1, wrapper2]:
>
> uses up the syntax forever.
I agree with Skip on this one, ANYTHING that transforms a function in
ANY way can be represented by this decorator syntax.
The only thing we can't change is the fact that Python will compile the
code block once before we get ahold of it, and we have no control over
the Python compiler/grammar while it is being compiled. These might be
more relevant for something like PyPy though, but there's nothing that
would really stop you from throwing keywords *inside* the [wrapper]
block if you need to let the compiler know about something if/when that
ever happens.
> (2) Wrappers are not essential to understanding functions,
> and should not pretend to be.
They are not essential to understanding how to make your own functions
or methods, but they are essential to understanding other people's code
that uses them:
def foo(args) [classmethod]:
pass
is quite different than what would happen otherwise. The default
behavior of code and class blocks is fine for most people, but once you
start doing a lot of metamagic and turn python into a domain specific
language, they become very relevant.
> In most languages, classifiers are always relevant. Defaults
> might save you from *writing* "int", "public", or "synchronized",
> but the classification still happens. If you want your code
> to be robust, you need to at least understand the possible
> classifiers, and when to use them. This means you need to
> learn something about each of them soon after "Hello World".
>
> In python, these extensions really are optional. The syntax
> should make it clear that newbies can ignore the whole
> construction, and do not need to know any specific wrappers.
>
> def func(args) [wrapper1, wrapper2]:
>
> suggests that the extensions are part of basic function syntax.
> Lack of documentation for wrapper1 and wrapper2 (which may not
> be part of the core language) presents an extra barrier. So
> does the fact that this is a new meaning for [], at least under
> the current patch. People can learn to ignore it -- but only if
> they have already committed to python. Each new barrier to
> entry makes a newbie more likely to give up before starting.
Since when do newbies read the "language lawyer" documentation? They
read the tutorials and existing code. No tutorials or existing code
(on top of the regular python compiler) use this syntax yet, so newbies
are obviously not going to see it.
-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20040303/8d2d9c4e/smime.bin
More information about the Python-Dev
mailing list