mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
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:
parent
72b068566a
commit
08a898f85d
2 changed files with 94 additions and 2 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue