[Python-Dev] Re: new syntax for wrapping (PEP 318)
Edward Loper
edloper at gradient.cis.upenn.edu
Wed Feb 25 19:11:06 EST 2004
Jim Jewett said:
> def f(arg) [x] : # wrap f in x
> def f(arg) : [x] # start f's def with a list of x
>
> [...]
>
> These are all well-defined for parsing, but I don't think the
> distinctions are obvious to a human who doesn't already know
> the syntax.
This point has come up a couple times, and I don't think it's really a
valid complaint, because...
* You won't get confused when reading it:
No one will ever write the second one (f's def consists of a single
list), because it's not a useful function. Has anyone ever
actually seen a function like this? So when you're reading the
code, you're very unlikely to get confused. This is especially
true because there will be an indented body under the f(arg), so the
[x] can't possibly be part of the body.
* If you write the wrong thing, it's easy to detect:
If you accidentally put the [x] after the colon, then you'll get
a parse error, since you'll *also* have a body. The current parse
error might be a little cryptic (just a syntax error at the first
line of the body), but if necessary the parser could be special-
cased to give a more specific error there.
Some of the other arguments against the new syntax seem reasonable to
me, and I'm not yet decided whether I'm in favor of the syntax or not.
But I just wanted to point out that I don't find this particular
complaint against it very compelling.
-Edward
More information about the Python-Dev
mailing list