[ python-Bugs-1060135 ] incorrect "'yield' outside function" error
SourceForge.net
noreply at sourceforge.net
Sat Nov 6 23:21:19 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: Closed
>Resolution: Invalid
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-06 17:21
Message:
Logged In: YES
user_id=80475
Sorry. No dice.
When you really understand what is happening,
the error message is dead-on. You need to
shift your mental model a bit.
The statements are executed without knowledge
of their surrounding context, only the dictionaries
can get shared.
When exec'd there is not enough information to
alter the message.
----------------------------------------------------------------------
Comment By: Willem Broekema (willemb)
Date: 2004-11-06 16:40
Message:
Logged In: YES
user_id=158280
It's the text of the error message that might be confusing;
something like "'yield' not allowed in 'exec'" would be better.
----------------------------------------------------------------------
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