[issue37830] continue in finally with return in try results with segfault

Ethan Furman report at bugs.python.org
Tue Aug 13 11:24:08 EDT 2019


Ethan Furman <ethan at stoneleaf.us> added the comment:

My apologies if I missed something, but do we have a consensus on the desired solution?

My understanding of `try/finally` is that whatever happens in the `finally` clause should:

- always happen
- win any conflicts with `try` clause

For example:

  try:
     a = 2
  finally:
     a = 3
  print(a)
  # 3

and

  def f():
     try:
        return 5
     finally:
        return 7
  print(f())
  # 7

So it seems like the ideal solution to:

  def mult(thing):
      print(thing*2)
      return thing * 2

  def simple():
      for number in range(2):
          try:
              return mult(number)
          finally:
              continue
  print(simple())

would be:

  0
  2
  None

----------
nosy: +ethan.furman

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37830>
_______________________________________


More information about the Python-bugs-list mailing list