Issue1784950

classification
Title: jython lambda doesn't behave like cpython lambda
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: musically_ut, thomasglee, thomaspollet, zyasoft
Priority: normal Keywords:

Created on 2007-08-30.16:09:28 by thomaspollet, last changed 2009-03-22.03:45:30 by zyasoft.

Messages
msg1888 (view) Author: Thomas Pollet (thomaspollet) Date: 2007-08-30.16:09:28
>>> filter(lambda x :x==1,[1,2])
[1]
>>> filter(lambda (x) :x==1,[1,2])
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "<console>", line 1, in <lambda>
TypeError: iteration over non-sequence


(the latter works in python)
msg1889 (view) Author: Utkarsh Upadhyay (musically_ut) Date: 2007-09-03.08:05:31
A little more exploratory work:

Jython 2.2:

>>>  filter( lambda (x):x==1, [(1,),(2,)] )
[(1,)]

While in Python 2.4:

>>> filter( lambda (x):x==1, [(1,),(2,)] )
[]

In fact, in a simpler example,

In Jython 2.2:

>>> f = lambda (x):x
>>> f(1)
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "<console>", line 1, in <lambda>
TypeError: iteration over non-sequence
>>> f((1,))
1
>>> f((1,2))
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "<console>", line 1, in <lambda>
ValueError: unpack tuple of wrong size
>>> 

While in Python 2.4: 

>>> f = lambda (x):x
>>> f(1)
1
>>> f((1,))
(1,)
>>> f((1,2))
(1, 2)
>>> 

It seems that Jython takes lambda (x) a little too literally, assuming that the argument passed will be only a single element tuple. While Python interprets it like any other function definition.

I will look into the matter further, time permitting.

HTH,
~musically_ut
msg1890 (view) Author: Tom Lee (thomasglee) Date: 2007-09-13.15:41:48
I've uploaded a naive fix for this here:

http://sourceforge.net/tracker/index.php?func=detail&aid=1793995&group_id=12867&atid=312867
msg3597 (view) Author: Jim Baker (zyasoft) Date: 2008-09-14.16:51:55
Fixed in 2.5
Need a unit test here
msg4330 (view) Author: Jim Baker (zyasoft) Date: 2009-03-22.03:45:30
test_complex_args provides ample test coverage of this now fixed bug.
History
Date User Action Args
2009-03-22 03:45:30zyasoftsetstatus: pending -> closed
messages: + msg4330
2008-09-14 16:51:55zyasoftsetstatus: open -> pending
title: lambda doesn't behave like python lambda -> jython lambda doesn't behave like cpython lambda
nosy: + zyasoft
messages: + msg3597
assignee: zyasoft
components: + Core, - None
resolution: fixed
2007-08-30 16:09:28thomaspolletcreate