On 1/01/20 11:28 am, Andrew Barnert via Python-ideas wrote:

The first is to extend unpacking assignment to target-or-expression lists. Like 
this:

    x, 0, z = vec

But
it doesn’t bind anything to the second element; instead, it checks if
that element is 0, and, if not, raises a ValueError.

What if you want to use an expression to represent a value to be
matched, rather than a literal? E.g.

K = 42

x, K, z = vec

The intention here that K is treated as a constant, but with your
semantics K would be bound to element 1 of vec.

The second is an “if try” statement, which tries an expression and
runs the body if that doesn’t raise (instead of if it’s truthy), but
jumps to the next elif/else/statement (swallowing the exception) if
it does.
If it truly swallows *any* exception, that's an extremely bad idea,
for all the same reasons that using a bare "except" clause is bad.

It might be acceptable if it only swallowed a special exception
such as PatternMatchError.

But then would be fairly specialised towards pattern matching,
so using the general word "try" doesn't seem appropriate. At that
point you might be better off with a dedicated "switch" or "case"
construct.

--
Greg
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7P2R3GFZG64NNMQ5GN55NUXWPDVAFYU7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to