Showing content from http://mail.python.org/pipermail/python-dev/attachments/20140223/cd9bd0fb/attachment-0001.html below:
<p dir="ltr"><br>
On Feb 23, 2014 7:52 PM, "Stefan Behnel" <<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>> wrote:<br>
><br>
> Chris Angelico, 21.02.2014 04:15:<br>
> > Just as PEP 308 introduced a means of value-based conditions in an<br>
> > expression, this system allows exception-based conditions to be used<br>
> > as part of an expression.<br>
> > [...]<br>
> > This currently works::<br>
> ><br>
> > Â Â lst = [1, 2, None, 3]<br>
> > Â Â value = lst[2] or "No value"<br>
> ><br>
> > The proposal adds this::<br>
> ><br>
> > Â Â lst = [1, 2]<br>
> > Â Â value = lst[2] except IndexError: "No value"<br>
><br>
> I see a risk of interfering with in-place assignment operators, e.g.<br>
><br>
> Â Â x /= y except ZeroDivisionError: 1<br>
><br>
> might not do what one could expect, because (as I assume) it would behave<br>
> differently from<br>
><br>
> Â Â x = x / y except ZeroDivisionError: 1</p>
<p dir="ltr">Yes. Augmented assignment is still assignment, so a statement. The only way to parse that is as</p>
<p dir="ltr">x /= (y except ZeroDivisionError: 1)</p>
<p dir="ltr">and it'd be equivalent to</p>
<p dir="ltr">x = x / (y except ZeroDivisionError: 1)</p>
<p dir="ltr">(If the parentheses are mandatory that makes it easier to spot the difference.)<br></p>
<p dir="ltr">><br>
> I think that falls under the "overly broad exception handling" issue. If<br>
> you want to include the assignment, you'll have to spell out the try-except<br>
> block yourself. I find the difference in the two behaviours very<br>
> unfortunate, though.<br>
><br>
> This also reduces the scope of applicability somewhat. Cython has typed<br>
> assignments, so a straight forward idea would be to handle TypeErrors in<br>
> assignments like this:<br>
><br>
> Â Â cdef str s<br>
> Â Â s = x except TypeError: str(x)<br>
><br>
> However, I guess that would similarly counter the idea of exception<br>
> handling in an *expression*, and the correct and non-ambiguous way to do<br>
> this would be to spell out the try-except block.<br>
><br>
> Summing it up, my impression is that it helps some use cases but leaves<br>
> others more ambiguous/unclear/unfortunate, which makes me lean towards<br>
> rejecting it.<br>
><br>
> Stefan<br>
><br>
><br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/thomas%40python.org">https://mail.python.org/mailman/options/python-dev/thomas%40python.org</a><br>
</p>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4