[New-bugs-announce] [issue6709] It's possible to create TryExcept with no handlers

Benjamin Peterson report at bugs.python.org
Sat Aug 15 04:39:54 CEST 2009


New submission from Benjamin Peterson <benjamin at python.org>:

I think we might need to devise some way to add custom validation when
AST is being compiled. For example, you can also pass a level to
ImportFrom which is < -1.

>>> x = ast.parse("try: x\nexcept y: pass")
>>> del x.body[0].handlers[:]
>>> compile(x, "<string>", "exec")
<code object <module> at 0x7f0a92aed918, file "<string>", line 1>
>>> from dis import dis
>>> dis(x)
>>> dis(compile(x, "<string>", "exec"))
  1           0 SETUP_EXCEPT             8 (to 11)
              3 LOAD_NAME                0 (x)
              6 POP_TOP
              7 POP_BLOCK
              8 JUMP_FORWARD             1 (to 12)
        >>   11 END_FINALLY
        >>   12 LOAD_CONST               0 (None)
             15 RETURN_VALUE

----------
components: Extension Modules, Interpreter Core
messages: 91587
nosy: benjamin.peterson
priority: normal
severity: normal
status: open
title: It's possible to create TryExcept with no handlers
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6709>
_______________________________________


More information about the New-bugs-announce mailing list