This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: It's possible to create TryExcept with no handlers
Type: behavior Stage: resolved
Components: Extension Modules, Interpreter Core Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, brett.cannon, georg.brandl, ncoghlan
Priority: normal Keywords:

Created on 2009-08-15 02:39 by benjamin.peterson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg91587 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-08-15 02:39
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
msg175237 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-11-09 14:12
This was fixed a while ago:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Try has neither except handlers nor finalbody
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50958
2012-11-09 14:31:13ezio.melottisetstage: needs patch -> resolved
2012-11-09 14:12:19benjamin.petersonsetstatus: open -> closed
resolution: out of date
messages: + msg175237
2012-11-09 14:10:05ezio.melottisetnosy: + brett.cannon, georg.brandl, ncoghlan
stage: needs patch

versions: + Python 3.3, Python 3.4, - Python 3.1
2010-07-11 09:14:36BreamoreBoysetversions: - Python 2.6, Python 2.5
2009-08-15 02:40:04benjamin.petersonsettype: behavior
2009-08-15 02:39:52benjamin.petersoncreate