The Most Diabolical Python Antipattern

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Jan 30 20:28:51 EST 2015


On 30/01/2015 08:10, Mark Lawrence wrote:
> On 30/01/2015 06:16, Marko Rauhamaa wrote:
>> Ian Kelly <ian.g.kelly at gmail.com>:
>>
>>> At least use "except Exception" instead of a bare except. Do you
>>> really want things like SystemExit and KeyboardInterrupt to get turned
>>> into 0?
>>
>> How about:
>>
>> ==============================
>>      try:
>>          do_interesting_stuff()
>>      except ValueError:
>>          try:
>>              log_it()
>>          except:
>>              pass
>>          raise
>> ==============================
>>
>> Surprisingly this variant could raise an unexpected exception:
>>
>> ==============================
>>      try:
>>          do_interesting_stuff()
>>      except ValueError:
>>          try:
>>              log_it()
>>          finally:
>>              raise
>> ==============================
>>
>> A Python bug?
>>
>>
>> Marko
>>
>
> It depends on the Python version that you're running - I think!!!  See
> https://www.python.org/dev/peps/pep-3134/
> https://www.python.org/dev/peps/pep-0409/
> https://www.python.org/dev/peps/pep-0415/ and finally try (groan :)
> https://pypi.python.org/pypi/pep3134/
>

http://bugs.python.org/issue23353 looks like fun and references PEP3134 
for anybody who's interested.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list