[XML-SIG] DOM Nodes: Identity test

Simon Pepping spepping@scaprea.hobby.nl
Thu, 25 Mar 1999 21:01:10 +0100


On Wed, Mar 24, 1999 at 10:22:13AM -0600, Paul Prescod wrote:
> "Andrew M. Kuchling" wrote:
> > 
> >         I've been wondering about that myself.  We don't want to
> > overload __cmp__ to do this, because Python comparisions are usually
> > done by value; 
> 
> We could agree that the only by-value check that makes sense is the
> identity check. This is the same as saying that the location of a node in
> the tree is part of its value. 
> 
> I note that the default "==" behaviour for new Python classes is to use
> the identity so there are probably dozens of Python classes in the
> standard distribution with this behaviour.
> 
> >>> class A:
> ...    pass
> ...
> >>> A()==A()
> 0

The question is: which comparison is used to check dictionary keys?
This is what the Python reference (2.1.6) says:
 
A mapping object maps values of one type (the key type) to arbitrary
objects. Mappings are mutable objects. There is currently only one
standard mapping type, the dictionary. A dictionary's keys are almost
arbitrary values. The only types of values not acceptable as keys are
values containing lists or dictionaries or other mutable types that
are compared by value rather than by object identity. Numeric types
used for keys obey the normal rules for numeric comparison: if two
numbers compare equal (e.g. 1 and 1.0) then they can be used
interchangeably to index the same dictionary entry.

That seems to endorse Paul's proposal.
 
-- 
Simon Pepping
email: spepping@scaprea.hobby.nl