Bug when using with_statement with exec

M

Matimus

I think I'm going to create a new issue in Pythons issue database, but
I wanted to run it by the news group first. See if I can get any
useful feed back.

The following session demonstrates the issue:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2
return 3
^
SyntaxError: invalid syntax



If I create a function by using exec on a string and _don't_ end the
string with a new-line it will work just fine unless I "from
__future__ import with_statement". I can imagine that it is probably a
good practice to always end function body's with a new-line, but the
requirement should be consistent and the syntax error text could be a
_little_ more descriptive (and flag something other than the 2nd to
last character). Note that you don't need to be in the interpreter to
reproduce this issue.

I searched python's issue database and didn't see anything similar to
this. If there is already an issue related to this, please point me to
it... or better yet, let me know how you found it.

Matt
 
J

Jerry Hill

If I create a function by using exec on a string and _don't_ end the
string with a new-line it will work just fine unless I "from
__future__ import with_statement". [snip]
I searched python's issue database and didn't see anything similar to
this. If there is already an issue related to this, please point me to
it... or better yet, let me know how you found it.

Possibly related to http://bugs.python.org/issue1184112, and/or
http://bugs.python.org/issue501622?

Since you asked, I found it by googling the words "python exec with
newline". The second item was an email on Python-Dev with a similar
bug and referencing an issue id. The comments on that issue led to
the other one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top