Performance of list vs. set equality operations
python at rcn.com
Thu Apr 8 17:16:09 CEST 2010
> So what happens in my example with a subclass that (falsely) reports a
> different length even when the lists are the same?
> I can guess that perhaps Py_SIZE does not call the subclass __len__
> method, and therefore is not fooled by it lying. Is that the case?
Yes. Py_SIZE() gets the actual size of the underlying list.
The methods for most builtin containers typically access the
underlying structure directly. That makes them fast and allows
them to maintain their internal invariants.
More information about the Python-list