Open henridwyer opened 9 years ago
It's unclear if the stderr part is https://github.com/LightTable/Python/blob/134751c32a86699c06ccafe46ae73a17a0e2d012/py-src/ltipy.py#L222 or https://github.com/LightTable/Python/blob/134751c32a86699c06ccafe46ae73a17a0e2d012/py-src/ltipy.py#L199 (those are my guesses).
The print_function bug is different... scoping of exec?
Edit: I can reproduce this locally:
In [2]: exec(compile("from __future__ import print_function", "hello.py", 'exec'))
In [3]: exec(compile("print('spam', file=sys.stderr)", "hello.py", 'exec'))
File "hello.py", line 1
print('spam', file=sys.stderr)
^
SyntaxError: invalid syntax
Had a look at the print_function bug. It appears to be related to the fact LightTable compiles each form in the file in sequence in py-src/ltmain.py
:
for form in toExec:
code = form[1]
loc = form[0]
#conditional stuff for eval vs. exec
code= compile(code, data[2]["name"], 'exec')
and the fact that the print_function is a monkey patch to syntax that exists only at runtime.
Attaching the from __future__ import print_function
line to the code in py-src/ltmain.py
allows something like print('spam', file=sys.stderr)
to be evaluated successfully:
if "print" in code:
code = "from __future__ import print_function\n" + code
code= compile(code, data[2]["name"], 'exec')
I'm not familiar with Python/LightTable internals, so can't propose an actual solution.
Edit: just realized that I've got an older version of the Python plugin installed, will need to check out the issue with the latest, but it looks like he basic problem remains the same.
When printing to stderr, nothing shows up in the console.
Both of these ways work if you replace stderr with stdout.
This raises an error for both stderr and stdout: