Issue2007

classification
Title: from __future__ import print_function doesn't work (at interactive prompt)
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: CecilWesterhof, fwierzbicki, irmen, jaraco, pjac, zyasoft
Priority: low Keywords:

Created on 2013-01-19.13:21:33 by irmen, last changed 2015-12-12.16:06:25 by jaraco.

Messages
msg7577 (view) Author: Irmen de Jong (irmen) Date: 2013-01-19.13:21:33
future's print_function doesn't work:

>>> from __future__ import print_function
>>> print("hello", end="test\n")
  File "<stdin>", line 1
    print("hello", end="test\n")
                     ^
SyntaxError: no viable alternative at input '='
>>>


Expected :


>>> from __future__ import print_function
>>> print("hello", end="test\n")
hellotest
>>>
msg7579 (view) Author: Irmen de Jong (irmen) Date: 2013-01-19.13:53:28
Note: this problem only occurs on the interactive prompt, when it is put in a module it works fine.
msg8110 (view) Author: Peter (pjac) Date: 2013-09-09.13:55:35
Confirming the print_function does not work at the Jython prompt (Mac OS X):

$ ~/jython2.7b1/jython
Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_24
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> print(1,2,3,4)
(1, 2, 3, 4)

Notice this is being interpreted as a print statement and a tuple.

Furthermore it does not seem to be working via a script which invokes doctests extracted from a file, specifically https://github.com/biopython/biopython/blob/54c1dbe984ef69c129c40be885f66b68836865f2/Tests/test_Tutorial.py from Biopython has stopped working following changes in the test style to use print functions. e.g.

<pre>
$ ~/jython2.7b1/jython test_Tutorial.py
Skipping tests needing the following:
 - numpy
Running Tutorial doctests...
**********************************************************************
File "test_Tutorial.py", line 150, in __main__.TutorialDocTestHolder.doctest_test_from_line_00601
Failed example:
    for index, letter in enumerate(my_seq):
        print(index, letter)
Expected:
    0 G
    1 A
    2 T
    3 C
    4 G
Got:
    (0, 'G')
    (1, 'A')
    (2, 'T')
    (3, 'C')
    (4, 'G')
**********************************************************************
...
</pre>

We have worked around this by modifying the print doctests:
https://github.com/biopython/biopython/commit/8bc8a9478be52b6a48741cd2406f8b210741fe71
msg8723 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.06:14:00
Interestingly, this works fine:

>>> from __future__ import print_function
>>> print(123)
123

But as reported, we still have this bug:

>>> print(1,2,3,4)
(1, 2, 3, 4)

Whereas as CPython works like so:

>>> from __future__ import print_function
>>> print(1,2,3,4)
1 2 3 4
msg8724 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.06:14:31
Target beta 4
msg10126 (view) Author: Cecil (CecilWesterhof) Date: 2015-06-21.12:40:45
At the moment I get:
======================================================================
>>> from __future__ import print_function
>>> print()
()
======================================================================

While it should be:
======================================================================
>>> from __future__ import print_function
>>> print()

======================================================================
msg10532 (view) Author: Jason R. Coombs (jaraco) Date: 2015-12-12.16:06:24
I'm seeing this behavior not at the interactive prompt. I'm using Jython in Moneydance (using the latest Extension patched for Jython 2.7.0 final https://bitbucket.org/infinitekind/moneydance_open/src/165efb396faffc05618900a7f2cd835f6c582d19?at=master) and I'm importing a module that's in sys.path whose header has `from future import print_function, unicode_literals`. When the program runs, literal strings are unicode but print is an expression. For example,

print("all's", "well")

renders as

(u"all's", u'well')

but should render as 

all's well

So it seems that it's more than just the interactive prompt affected by the print_function future not being recognized.
History
Date User Action Args
2015-12-12 16:06:25jaracosetnosy: + jaraco
messages: + msg10532
2015-06-21 12:40:45CecilWesterhofsetnosy: + CecilWesterhof
messages: + msg10126
2014-06-19 06:14:31zyasoftsetmessages: + msg8724
2014-06-19 06:14:00zyasoftsetnosy: + zyasoft
messages: + msg8723
2013-09-09 13:55:35pjacsetnosy: + pjac
messages: + msg8110
2013-02-20 00:23:41fwierzbickisetpriority: low
nosy: + fwierzbicki
versions: + Jython 2.7, - 2.7a2
2013-01-19 13:53:29irmensetmessages: + msg7579
title: from __future__ import print_function doesn't work -> from __future__ import print_function doesn't work (at interactive prompt)
2013-01-19 13:21:33irmencreate