[Python-ideas] Providing a guarantee that instances of user-defined classes have distinct identities

Max Moroz maxmoroz at gmail.com
Wed Apr 18 18:49:43 CEST 2012

After reading the comments, and especially the one below, I am now
persuaded that this implied guarantee is sufficient.

Part of the problem was that I didn't have a clear picture of what
__new__ is supposed to do when called with a (proper) subclass
argument. Now I (hopefully correctly) understand that a well-behaved
__new__ should in this case simply pass the call to object.__new__, or
at least do something very similar: the subclass has every right to
expect this behavior to remain unchanged whether or not one of its
parent classes defined a custom __new__. No explicit guarantee is
needed to confirm that this is what built-in classes do.

Steven D'Aprano wrote:
> "Calling len() on a list will never randomly shuffle the list as a
> side-effect."
> The fact that len() doesn't shuffle the list as a side-effect is not a
> documented promise of the language. But does it have to be? Some things
> would be just stupid for any implementation to do. There is no limit to the
> number of stupid things an implementation might do, and for the language to
> specify that it doesn't do any of them is impossible.

More information about the Python-ideas mailing list