why () is () and [] is [] work in other way?

Adam Skutt askutt at gmail.com
Thu Apr 26 20:08:25 EDT 2012


On Thu, Apr 26, 2012 at 5:39 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Thu, Apr 26, 2012 at 1:34 PM, Adam Skutt <askutt at gmail.com> wrote:
>> What I think you want is what I said above: ValueError raised when
>> either operand is a /temporary/ object.  Really, it should probably be
>> a parse-time error, since you could (and should) make the
>> determination at parse time.
>
> I'm not sure precisely what you mean by "temporary object", so I am
> taking it to mean an object that is referenced only by the VM stack
> (or something equivalent for other implementations).
>
> In that case: no, you can't.  Take "f() is g()", where the code
> objects of f and g are supplied at runtime.  Are the objects returned
> by either of those expressions "temporary"?  Without being able to do
> static analysis of the code of f and g, there is no way to know.

A temporary object would be anything that need not be alive longer
than the duration of the 'is' operation.  I am not a Python language
expert so that definition may not be exactly correct or workable for
Python.

In the example:
>>> [1, 2] is [3, 4]

[1,2] and [3,4] don't need to exist before the 'is' operation, nor
after it, so they are temporaries.

Adam



More information about the Python-list mailing list