[issue35916] 3.6.5 try/except/else/finally block executes code with typos, no errors

DMITRY KOSHELEV report at bugs.python.org
Wed Feb 6 11:18:38 EST 2019


New submission from DMITRY KOSHELEV <koshelevdi at gmail.com>:

Hello dear developer!
I was playing with try/else/finally block and have found a bug:

Inside of "else" or/and "except" I can do this 
  1 + print('Why do you print me?') + 1
this would print "Why do you print me?", 
in case if I have "finally" block with a "return" statement, no error raises,
if I don't have finally, nothing is printed.

def foo(var):
  try:
    print("Hello")
    # 1 + print("Hello")
    except:
      1 + print('Why do you print me?') + 1
    else:
      1 + print('Why do you print me?') + 1
    finally:
      print("finally block")
      return

----------
files: bug_in_try_exceptions.py
messages: 334950
nosy: dmitry_koshelev
priority: normal
severity: normal
status: open
title: 3.6.5 try/except/else/finally block executes code with typos, no errors
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file48107/bug_in_try_exceptions.py

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


More information about the Python-bugs-list mailing list