Terry J. Reedy added the comment:

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.

----------
nosy: +terry.reedy
resolution:  -> rejected
stage:  -> committed/rejected
status: open -> closed
versions:  -Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17294>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to