[New-bugs-announce] [issue1875] "if 0: return" not raising SyntaxError

Armin Rigo report at bugs.python.org
Sat Jan 19 19:55:50 CET 2008


New submission from Armin Rigo:

Can you guess why importing the attached x.py does nothing, without
printing "hello" at all?

The real issue shown in that example is that 'return' and 'yield'
outside a function are ignored instead of giving a SyntaxError if they
are optimized away by 'if 0:'.  

(Hint about x.py: the yield sets the CO_GENERATOR flag before it gets
optimized away.  So clearly, that's a way to comment out a whole module
-- just put "if 0: yield" anywhere at top-level...)

----------
components: Interpreter Core
files: x.py
messages: 60213
nosy: arigo
priority: low
severity: minor
status: open
title: "if 0: return" not raising SyntaxError
versions: Python 2.6
Added file: http://bugs.python.org/file9231/x.py

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1875>
__________________________________


More information about the New-bugs-announce mailing list