Another "if 0:" hack, this time to complain about otherwise invisible

"return expr" instances in generators (which latter may be generators
due to otherwise invisible "yield" stmts hiding in "if 0" blocks).
This was fun the first time, but this has gotten truly ugly now.
This commit is contained in:
Tim Peters 2001-06-28 01:52:22 +00:00
parent 72b068566a
commit 08a898f85d
2 changed files with 94 additions and 2 deletions

View file

@ -651,6 +651,17 @@ But this is fine:
>>> list(f())
[12, 666]
>>> def f():
... yield
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> def f():
... if 0:
... yield
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> def f():
... if 0:
... yield 1
@ -704,6 +715,28 @@ But this is fine:
... yield 2
>>> type(f())
<type 'None'>
>>> def f():
... if 0:
... return
... if 0:
... yield 2
>>> type(f())
<type 'generator'>
>>> def f():
... if 0:
... lambda x: x # shouldn't trigger here
... return # or here
... def f(i):
... return 2*i # or here
... if 0:
... return 3 # but *this* sucks (line 8)
... if 0:
... yield 2 # because it's a generator
Traceback (most recent call last):
SyntaxError: 'return' with argument inside generator (<string>, line 8)
"""
__test__ = {"tut": tutorial_tests,