Message681

Author nobody
Recipients
Date 2002-07-04.12:45:54
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
This program (also attached):

x = []
def trying():
    try:
        try:
            x.append(1)
            return
        finally:
            x.append(2)
    finally:
        x.append(3)

trying()
assert x == [1,2,3], repr(x)


outputs:

AssertionError: [1, 2]

Ie. the outer finally is not executed at return.


The workaround is simple: return after the last finally
and store an evt. return value in a temporary variable.
I did not experiment with raising exceptions instead
of returning.

In my case this bug caused a lock not to be released :)

Have fun,
Ype

ykingma@xs4all.nl
History
Date User Action Args
2008-02-20 17:17:07adminlinkissue577395 messages
2008-02-20 17:17:07admincreate