Semantics of ==

Michael Hudson mwh at python.net
Wed Mar 17 17:00:58 CET 2004


Andrew Bennetts <andrew-pythonlist at puzzling.org> writes:

> On Tue, Mar 16, 2004 at 07:07:27PM -0500, John Roth wrote:
> > "Axel Boldt" <axelboldt at yahoo.com> wrote in message
> > news:40200384.0403161538.7407d9e2 at posting.google.com...
> [...]
> > >   >>> s
> > >   [1, [...]]
> > >   >>> w
> > >   [1, [1, [...]]]
> > >   >>> s==w
> > >   True
> [...]
> > 
> > I think the original True is a bug. It's getting confused
> > by the recursion.
> 
> I don't think it's a bug.  In what sense are they unequal?  Both variables
> are a sequence of two elements, the integer 1, and a sequence that's equal
> to the outer sequence (i.e. s==s[1] is True, as Python will tell you).
> Every element of the sequence s is equal to the corresponding element of the
> sequence w, as far as I can see, even though there is infinite recursion.
> 
> Python is behaving exactly as I would expect it to.  (Although in the face
> of such pathological data structures, I wouldn't mind terribly much if it
> didn't...)

It will raise RuntimeError (or somesuch) in Python 2.4.

Cheers,
mwh

-- 
  #ifndef P_tmpdir
  printf( "Go buy a better computer" );
  exit( ETHESKYISFALLINGANDIWANTMYMAMA );
                         -- Dimitri Maziuk on writing secure code, asr



More information about the Python-list mailing list