[issue1875] "if 0: return" not raising SyntaxError
Amaury Forgeot d'Arc
report at bugs.python.org
Tue Feb 3 00:48:27 CET 2009
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
Here is a patch that properly raises SyntaxError when 'return' or
'yield' statements appear outside a function.
I did not bother to update the (deprecated) compiler package: it seems
to be completely foreign to this kind of checks...
>>> dis.dis(compiler.compile("return 1", "module.py", "exec"))
1 0 LOAD_CONST 1 (1)
3 RETURN_VALUE
4 LOAD_CONST 0 (None)
7 RETURN_VALUE
----------
assignee: -> amaury.forgeotdarc
keywords: +needs review, patch
resolution: fixed ->
status: closed -> open
Added file: http://bugs.python.org/file12926/return_outside_func.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1875>
_______________________________________
More information about the Python-bugs-list
mailing list