On Mon, Feb 24, 2014 at 7:51 AM, Ethan Furman <et...@stoneleaf.us> wrote:
>> Yes. Augmented assignment is still assignment, so a statement. The only
>> way to parse that is as
>>
>> x /= (y except ZeroDivisionError: 1)
>
>
> Well, that is certainly not what I would have expected.

I can see that you'd want to have that go back and redo the division
with a second argument of 1, which'd look like this in statement form:

try: x /= y
except ZeroDivisionError: x /= 1

But, just like the decried error suppression technique, the second
half of this is something that should instead be written "pass". At
very least, I'd say that an except-expression where one or other of
its forms is better spelled "pass" is code smell, and at worst, I'd
say it's a hint that the expression form might not even be what you
think it is - as in this case.

Remember, this is a scope-narrowing. Where previously you had to
try/except entire statements, now you can try/except just one part of
something. That means you won't catch errors in the actual assignment
- which is usually a good thing - but it does affect augmented
assignment. My recommendation: Just use try... except pass. I'm not
trying to supplant the statement form :)

ChrisA
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
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