[New-bugs-announce] [issue6740] Compounded expressions with lambda functions are evaluated incorrectly

Michal Vyskocil report at bugs.python.org
Thu Aug 20 12:27:17 CEST 2009


New submission from Michal Vyskocil <mvyskocil at suse.cz>:

The compounded expressions with lambda functions are evaluated
incorrectly. The simple expressions, or a named functions are evaluated
good. The problem is only in the evaluation of compounded expressions.
It seems that after evaluate of the first lambda function the
evaluation of whole expression is stopped and not continue (see
cond_error, which may raises the exception during evaluation).

Python 3.1 (r31:73572, Aug 15 2009, 22:04:19)
[GCC 4.4.1 [gcc-4_4-branch revision 149935]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> cond = (lambda x : x == 'foo') or (lambda x : x == 'bar')
>>> cond('foo')
True
>>> cond('bar')
False
>>> c1 = lambda x : x == 'foo'
>>> c1('foo')
True
>>> c2 = lambda x : x == 'bar'
>>> c2('bar')
True
>>> def ham(x): return x == 'foo'
...
>>> def spam(x): return x == 'bar'
...
>>> cond2 = lambda x : ham(x) or spam(x)
>>> cond2('foo')
True
>>> cond2('bar')
True
>>> cond2('ham')
False
>>> cond_error = (lambda x : x == 'foo') or (lambda x : y == 'bar')
>>> cond_error('d')
False

BTW: the same problem exists in Python 2.6.2
Python 2.6.2 (r262:71600, Aug 15 2009, 18:37:04)
[GCC 4.4.1 [gcc-4_4-branch revision 149935]] on linux2
Type "help", "copyright", "credits" or "license" for more information.

----------
messages: 91766
nosy: mvyskocil
severity: normal
status: open
title: Compounded expressions with lambda functions are evaluated incorrectly
versions: Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6740>
_______________________________________


More information about the New-bugs-announce mailing list