Re: [Python-Dev] Why not make frames? [was: Alternative forms [was: PEP 463: Exception-catching expressions]]

2014年3月12日 10:29:05 -0700

On 2014年3月10日 14:26:14 +1100, Chris Angelico <[email protected]> wrote:
> On Mon, Mar 10, 2014 at 1:16 PM, Jim J. Jewett <[email protected]> wrote:
> > I don't claim that syntax is perfect. I do think it is less flawed
> > than the no-parentheses (or external parentheses) versions:
> >
> > (expr1 except expr3 if expr2)
> > expr1 except expr3 if expr2
> >
> > because the tigher parentheses correctly indicate that expr2 and expr3
> > should be considered as a (what-to-do-in-case-of-error) group, which
> > interacts (as a single unit) with the main expression.
> 
> But it doesn't, really. The entire set of three expressions is a
> single unit. You can't break out the bit inside the parens and give
> that a name, like you can in most places where something "acts as a
> single unit" to interact with something else. (Yes, there are special
> cases, like the syntax for constructing slice objects that works only
> inside square brackets. And you can't break out a function's
> arguments, as a unit, into a single object (the nearest is
> *args,**kw). I said most places, and I don't want to add more to the
> special-case set.)
Actually, function arguments almost aren't a special case any more:
>>> import inspect
>>> def a(a, b=2):
... print(a, b)
... 
>>> def b(c, d=3):
... print(c, d)
... 
>>> sa = inspect.signature(a)
>>> print(sa)
(a, b=2)
>>> ba = sa.bind(1, 2)
>>> b(*ba.args, **ba.kwargs)
1 2
Note: I said *almost* :) But the point is that we found that the fact
that we couldn't give this thing in parens a name bothersome enough
to partially fix it.
--David
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to