diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-06-28 01:52:22 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-06-28 01:52:22 (GMT) |
commit | 08a898f85d69c060241dc7f07f003e6e6c4acd50 (patch) | |
tree | 79da11e3bbe1c616a0193b96299fa469d51c1f17 /Lib/test/test_generators.py | |
parent | 72b068566ace24bb49c935ba4c539f021212249a (diff) | |
download | cpython-08a898f85d69c060241dc7f07f003e6e6c4acd50.zip cpython-08a898f85d69c060241dc7f07f003e6e6c4acd50.tar.gz cpython-08a898f85d69c060241dc7f07f003e6e6c4acd50.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/test_generators.py')
-rw-r--r-- | Lib/test/test_generators.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 3dd468b..7b78b2b 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -652,6 +652,17 @@ But this is fine: [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 >>> type(f()) @@ -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, |