On 07/08/2020 17:16, Serhiy Storchaka wrote:
The main problem to me with the exception catching expression is that
you need to add the exception name and several keywords, and it makes
real-world examples too long, so you will need to split the expression
on several lines, and add extra parenthesis. And in this case there is
no much difference between expression
x = (
<long expression>
except LongExceptionName:
<other long expression>
)
and statement
try:
x = <long expression>
except LongExceptionName:
x = <other long expression>
(actually the statement may be shorter and better aligned).
This is a strawman argument. You set up a case where exception-catching
expressions are poor (long expression, long exception name) and then
knock it down. If you read the PEP you will find plenty of short examples:
process(dic[key] except KeyError: None)
value = (lst[2] except IndexError: "No value")
cond = (args[1] except IndexError: None)
pwd = (os.getcwd() except OSError: None)
e.widget = (self._nametowidget(W) except KeyError: W)
line = (readline() except StopIteration: '')
etc.
Other problem specific to the PEP 463 syntax is using colon in
expression. Colon is mainly used before indented block in complex
statements. It was introduced in this role purely for aesthetic reasons.
Using it in other context is very limited (dict display, lambda,
annotations, what else?).
Slice notation. As you would have discovered if you read the PEP.
Dict display and slices are hardly of "very limited" use. (I can't
comment on annotations, I don't use them.)
Even the "if" expression does not use it.
_______________________________________________
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/6EYZ2DLJZ7YOZPS4PYJD2UHBKZU7WEHT/
Code of Conduct: http://python.org/psf/codeofconduct/