Issue2459

classification
Title: Triple quotes are not parsed properly by the console
Type: Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, jsaiz, zyasoft
Priority: Keywords:

Created on 2016-02-03.12:52:05 by jsaiz, last changed 2016-02-03.20:11:31 by zyasoft.

Messages
msg10703 (view) Author: Jaime (jsaiz) Date: 2016-02-03.12:52:04
In Python (so therefore in Jython), it is possible to write multiline comments by putting the text between triple quotes:

"""
this is a
multiline comment
"""

However, in Jython 2.7.0 the interpreter no longer waits for the user to complete the string, but the initial triple quote is somehow considered a valid command (although doing nothing), so the comment cannot be completed:

linux> jython2.5
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> """
... this is a 
... multiline comment
... """
'\nthis is a\nmultiline comment\n'

linux> jython2.7
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> """
>>> this is a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'this' is not defined


Is this a regression? Or is it intended behaviour?
msg10709 (view) Author: Jim Baker (zyasoft) Date: 2016-02-03.20:11:31
Also true of the Jython 2.5 branch (which we would be unlikely to fix).

For both Jython 2.5 branch and 2.7, triple quotes are simply ignored by the Jython console. To support interactive completions over multiple lines, the console uses a special grammar (and I believe a special set of tokenization rules, hence this problem), when compared to directly compiling files. 

You can see this behavior at this point in Jython 2.7:

>>> """
>>> this is a

vs what should be the case:

>>> """
... this is a

No interactive completion allowed - the triple quotes are simply ignored. But context matters; this assignment works fine in Jython 2.7:

>>> x = """Jython should not ignore this content
...
... """
>>> x
'Jython should not ignore this content\n\n'
History
Date User Action Args
2016-02-03 20:11:31zyasoftsetnosy: + zyasoft, fwierzbicki
resolution: accepted
messages: + msg10709
title: Triple quotes are now considered a complete command (?) -> Triple quotes are not parsed properly by the console
2016-02-03 12:52:05jsaizcreate