[Python-ideas] Make return inside a finally a SyntaxError
Michael
fuzzyman at gmail.com
Sat Jul 18 02:17:37 CEST 2009
--
http://www.ironpythoninaction.com
On 18 Jul 2009, at 01:13, Collin Winter <collinw at gmail.com> wrote:
> On Fri, Jul 17, 2009 at 5:00 PM, Michael<fuzzyman at gmail.com> wrote:
>> On 18 Jul 2009, at 00:44, Collin Winter <collinw at gmail.com> wrote:
>>
>>> On Fri, Jul 17, 2009 at 4:41 PM, Michael<fuzzyman at gmail.com> wrote:
>>>>
>>>> Here are two examples of why allowing return inside a finally
>>>> block is a
>>>> bad
>>>> idea:
>>>>
>>>> def f():
>>>> try:
>>>> return 3
>>>> finally:
>>>> return 4
>>>
>>> Do you have real code that suffers from this problem? Is this a
>>> common
>>> mistake for Python beginners?
>>
>> Not specifically but I think it is an unfortunate design decision
>> that
>> should be corrected.
>
> Do you believe
>
> def f():
> try:
> raise OSError
> finally:
> raise KeyError
>
> should be a SyntaxError, too?
No, the semantics of exceptions raised in finally blocks are pretty
clear.
Michael
>
> Collin Winter
More information about the Python-ideas
mailing list