weird try/finally behaviour

Aaron Brady castironpi at
Sat Apr 11 09:34:05 CEST 2009

On Apr 10, 7:19 pm, Terry Reedy <tjre... at> wrote:
> Sylvain Thénault wrote:
> > Hi there,
> > I've encountered the following behaviour which I found surprising:
> If you say 'print test()', you shoud see None printed after 'end' (at
> least with 3.0) from the function falling off the end.
> The 'if True:' line make no difference.
> > As you can see, the 'break' in the finally block makes the 'return 1' beeing ignored.
> > Is this a known caveat or should it be considered as a bug?
> Neither, but it s a bit subtle.  If you replace 'break' with 'return 2'

Ha!  Brilliant.

More information about the Python-list mailing list