This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mseaborn
Recipients mseaborn
Date 2008-11-05.10:56:27
SpamBayes Score 1.9570339e-09
Marked as misclassified No
Message-id <1225882648.97.0.627285996609.issue4262@psf.upfronthosting.co.za>
In-reply-to
Content
compile() raises a SyntaxError if the source code it is given contains
trailing spaces or a trailing carriage return character, but this does
happen if the same source code is imported or executed.

import subprocess

data = "if True:\n  pass\n  "
filename = "/tmp/test.py"
fh = open(filename, "w")
fh.write(data)
fh.close()
subprocess.check_call(["python", filename])
subprocess.check_call(["python", "-c", "import test"], cwd="/tmp")
compile(data, filename, "exec")


This gives:

Traceback (most recent call last):
  File "whitespace.py", line 11, in <module>
    compile(data, filename, "exec")
  File "/tmp/test.py", line 3
    
SyntaxError: invalid syntax

This also happens if the data is changed to:
data = "if True:\n  pass\r"
History
Date User Action Args
2008-11-05 10:57:29mseabornsetrecipients: + mseaborn
2008-11-05 10:57:28mseabornsetmessageid: <1225882648.97.0.627285996609.issue4262@psf.upfronthosting.co.za>
2008-11-05 10:56:28mseabornlinkissue4262 messages
2008-11-05 10:56:27mseaborncreate