[ python-Bugs-1060135 ] incorrect "'yield' outside function" error

SourceForge.net noreply at sourceforge.net
Fri Nov 5 18:12:27 CET 2004


Bugs item #1060135, was opened at 2004-11-04 06:25
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1060135&group_id=5470

>Category: Documentation
Group: None
Status: Open
Resolution: None
>Priority: 1
Submitted By: Willem Broekema (willemb)
Assigned to: Nobody/Anonymous (nobody)
Summary: incorrect "'yield' outside function" error

Initial Comment:
In fact, the yield _is_ inside a function in the
following case:

>>> def f():
...   a = 3
...   exec("yield a")
...
>>> g = f()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in f
  File "<string>", line 1
SyntaxError: 'yield' outside function


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-11-05 12:12

Message:
Logged In: YES 
user_id=80475

Statements in an exec get interpreted and executed as a unit
and cannot affect surrounding control flow.  For example:
   for i in range(10):
       exec('continue')   # won't work

This is an intrinsic limitation and not a bug.  Perhaps the
docs could be improved though.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1060135&group_id=5470


More information about the Python-bugs-list mailing list