Message2882

Author thomasglee
Recipients
Date 2007-09-13.15:38:19
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Attached is a patch fixing 1784950. Effectively, for the following code:

def foo((x)):
  pass

Jython was treating (x) as though it were a tuple due to a small bug in the grammar (as you're probably aware, a single-element tuple in python must end with a comma e.g. (x,). This patch modifies the grammar slightly to handle this weird syntax.

I have a feeling that Jython is still treating tuples somewhat weirdly based on the following output vs. Python 2.4:

---

tom@local:~/src/personal/jython-trunk/jython$ java -jar dist/jython.jar test.py 
foo(5) - without fplist
{'x': 5}

foofp(5) - with fplist
{'x': 5}

lambda_foo(5) - without fplist
{'x': 5}

lambda_foofp(5) - with fplist
{'x': 5}

multi((5, 6)) - with fplist
{'(x, y)': (5, 6), 'x': 5, 'y': 6}

tom@local:~/src/personal/jython-trunk/jython$ python test.py
foo(5) - without fplist
{'x': 5}

foofp(5) - with fplist
{'x': 5}

lambda_foo(5) - without fplist
{'x': 5}

lambda_foofp(5) - with fplist
{'x': 5}

multi((5, 6)) - with fplist
{'y': 6, 'x': 5, '.0': (5, 6)}

---

Note that it behaves just like ordinary python, with the exception of multi() - which creates a local named '.0' in Py2.4 and '(x, y)' in Jy2.3a0. Weird.

Please note this is my first patch and the first time I've touched JavaCC - my changes to fpdef and fplist make the grammar a little less elegant, but hopefully somebody who knows Jython a little better than I can help make this patch worthwhile.
History
Date User Action Args
2008-02-20 17:18:49adminlinkissue1793995 messages
2008-02-20 17:18:49admincreate