Print output implicitly for one line evals
Link to discussion
Should the eval command !e with an inline codeblock or no codeblock at all be ran and the output printed by default? (This is similar to how the Python REPL functions:
python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "Hello, world"
'Hello, world'
>>>
Similarly,
!e "Hello, world!"
'Hello, world!'
After discussing this further with @ionite34, I'm rejecting this idea in favour of #2369. While this seemed good on paper, the trickiness of the implementation details makes this a bad idea:
- If the one-liner already has print() then !eval will output None ... and then the rest of the output which would be confusing (we could check for whether print is already present, but that'd be fragile)
- Statements would break (we could catch SyntaxError and try again without the implicit print call being wrapped, but that's messy)
- Semicolons have no chance of working
And interacting with the Python REPL programmatically is apparently hard to do so that can't be done either which leaves us without any good options. Sorry for wasting everyone's time :(
With #2369 as-is, you'd do !e -i <one-liner> and it would show the eval result (just like IPython).