[Python-ideas] One more time... lambda function <--- from *** signature def.
Chris Angelico
rosuav at gmail.com
Tue Mar 4 15:14:09 CET 2014
On Tue, Mar 4, 2014 at 11:50 PM, Masklinn <masklinn at masklinn.net> wrote:
> On 2014-03-04, at 13:07 , Chris Angelico <rosuav at gmail.com> wrote:
>> Most people expect that:
>>
>> foo = bar
>> assert foo is bar
>>
>> to be a safe assumption, but if bar is a thunk, then it's getting
>> evaluated separately in each of those
>
> Why? Either it's forced during assignment or both names map to
> the same thunk, and are both forced when any of them is.
>
> That could be during the identity check, but since both names refer to
> the same thunk they can only yield the same value, so the identity check
> needs not force the thunk. An equality test would likely force the
> thunk.
Most certainly not. Try this:
bar = `[1,2,3]`
foo = bar
spam = bar
assert foo is spam
Here's the evaluated version:
foo = [1,2,3]
spam = [1,2,3]
assert foo is spam
You can try this one out directly. They're not going to be the same
object - they'll be two separate lists. They will be equal, in this
case, but there's no guarantee of that either:
bar = `random.random()`
Separate evaluation of the same expression isn't guaranteed to have
the same result, AND it might have unexpected side effects:
bar = `whiskey.pop().drink()`
and you might find yourself underneath the bar before you know it.
ChrisA
More information about the Python-ideas
mailing list