Issue2007
Created on 2013-01-19.13:21:33 by irmen, last changed 2019-05-15.10:43:09 by adamburke.
Files | ||||
---|---|---|---|---|
File name | Uploaded | Description | Edit | Remove |
print_doctest.py | pjac, 2017-04-05.15:25:23 |
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. |
|||
msg11298 (view) | Author: Peter (pjac) | Date: 2017-04-05.15:25:23 | |
I can confirm this does not just fail at the interactive prompt, it also fails in the context of doctests. Test case provided: Desired output shown from (Apple provided) Python 2.7.10 on macOS, $ python print_doctest.py Trying: print(1, 2, 3) Expecting: 1 2 3 ok 1 items passed all tests: 1 tests in __main__ 1 tests in 1 items. 1 passed and 0 failed. Test passed. Darwin-16.4.0-x86_64-i386-64bit 2.7.10 (default, Jul 30 2016, 19:40:32) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] Desired output shown from (self-compiled) Python 3.6 on macOS, $ python3.6 print_doctest.py Trying: print(1, 2, 3) Expecting: 1 2 3 ok 1 items passed all tests: 1 tests in __main__ 1 tests in 1 items. 1 passed and 0 failed. Test passed. Darwin-16.4.0-x86_64-i386-64bit 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] Problematic output from Jython 2.7 installed using jython-installer-2.7.0.jar on macOS, $ jython print_doctest.py Trying: print(1, 2, 3) Expecting: 1 2 3 ********************************************************************** File "print_doctest.py", line 16, in __main__ Failed example: print(1, 2, 3) Expected: 1 2 3 Got: (1, 2, 3) ********************************************************************** 1 items had failures: 1 of 1 in __main__ 1 tests in 1 items. 0 passed and 1 failed. ***Test Failed*** 1 failures. Java-1.8.0_121-Java_HotSpot-TM-_64-Bit_Server_VM,_25.121-b13,_Oracle_Corporation-on-Mac_OS_X-10.12.3-x86_64 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] The test script: $ cat print_doctest.py """Jython print_function doctest example. Under Python 2 by default, print(1, 2, 3) would be seen as a print statement given a tuple, and give: (1, 2, 3) Under Python 3 by default, it would be seen as a call to the print function and give: 1 2 3 Let's try it in a doctest where we've explicitly asked for a print function via the future import. >>> print(1, 2, 3) 1 2 3 """ from __future__ import print_function import doctest import sys import platform doctest.testmod(verbose=2) print(platform.platform()) print(sys.version) |
|||
msg12522 (view) | Author: Adam Burke (adamburke) | Date: 2019-05-15.10:43:09 | |
The standalone print operator should also cause a syntax error when using from __future__ import print_function. On the console it doesn't. -c and script works. C:\Users\Adam\jython\jython6\jython>dist\bin\jython.exe Jython 2.7.2a1+ (, May 14 2019, 12:59:32) [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java11.0.1 Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import print_function >>> >>> print 'test' test >>> C:\Users\Adam\jython\jython6\jython>dist\bin\jython.exe -c "from __future__ import print_function; print 'test' " File "<string>", line 1 from __future__ import print_function; print 'test' ^ SyntaxError: no viable alternative at input ''test'' |
History | |||
---|---|---|---|
Date | User | Action | Args |
2019-05-15 10:43:09 | adamburke | set | nosy:
+ adamburke messages: + msg12522 |
2017-04-05 15:25:24 | pjac | set | files:
+ print_doctest.py messages: + msg11298 |
2015-12-12 16:06:25 | jaraco | set | nosy:
+ jaraco messages: + msg10532 |
2015-06-21 12:40:45 | CecilWesterhof | set | nosy:
+ CecilWesterhof messages: + msg10126 |
2014-06-19 06:14:31 | zyasoft | set | messages: + msg8724 |
2014-06-19 06:14:00 | zyasoft | set | nosy:
+ zyasoft messages: + msg8723 |
2013-09-09 13:55:35 | pjac | set | nosy:
+ pjac messages: + msg8110 |
2013-02-20 00:23:41 | fwierzbicki | set | priority: low nosy: + fwierzbicki versions: + Jython 2.7, - 2.7a2 |
2013-01-19 13:53:29 | irmen | set | messages:
+ 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:33 | irmen | create |
Supported by Python Software Foundation,
Powered by Roundup