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 terry.reedy
Recipients Albert.Zeyer, georg.brandl, terry.reedy
Date 2013-10-18.22:42:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382136127.74.0.85231198454.issue17294@psf.upfronthosting.co.za>
In-reply-to
Content
Albert: enhancements can only go in future releases.

Also, when a core developer rejects a suggestion and closes an issue, it is better to just request a re-open, or otherwise post to python-list or python-ideas to refine the idea and possible gather more support. We really do not like Status header setting wars.

Mode 'single' is not what you actually want. Its only purpose is add the print that you do not want*. It is otherwise the same as mode 'exec' (except for requiring exactly 1 statement rather than 0 to n). What you are asking is that 'single' act like 'eval' for expressions.  That is what your interactive_py_compile effectively does. However, this can be done much easier and without being CPython 2 specific as follows:

def ee_compile(code, src=''):
    try:
        return compile(code, src, 'eval')
    except SyntaxError:
        return compile(code, src, 'exec')  # or 'single' would work

a = eval(ee_compile('1+1'))
b = eval(ee_compile('c = 3'))
print(a, b, c)
# 2 None 3

With 2.7, your function gives the exact same result. I could not get it to run on 3.3: even after removing the ord calls and changing chr to bytes (and making the arg a tuple), the CodeType call failed.

* I believe the only reason 'single' exists, as a variant of 'exec', is to make loops like the following print non-None values of expressions but otherwise ignore them.

for statement in user_input():
  if statement:
    exec(compile(statement, '<input>', 'single'))

You can replace the last line with
    v = eval(ee_compile(statement, '<input>', 'single'))
    process(v)

Anyway, I agree with Georg that we do not need to modify compile. I have opened a separate issue #19290 about clarifying compile modes and their interaction with eval.
History
Date User Action Args
2013-10-18 22:42:07terry.reedysetrecipients: + terry.reedy, georg.brandl, Albert.Zeyer
2013-10-18 22:42:07terry.reedysetmessageid: <1382136127.74.0.85231198454.issue17294@psf.upfronthosting.co.za>
2013-10-18 22:42:07terry.reedylinkissue17294 messages
2013-10-18 22:42:07terry.reedycreate