[Python-Dev] == on object tests identity in 3.x (original) (raw)

Ethan Furman ethan at stoneleaf.us
Tue Jul 8 04:25:58 CEST 2014


On 07/07/2014 06:58 PM, Steven D'Aprano wrote:

On Mon, Jul 07, 2014 at 04:52:17PM -0700, Ethan Furman wrote:

On 07/07/2014 04:49 PM, Benjamin Peterson wrote:

Probably the best argument for the behavior is that "x is y" should imply "x == y", which preludes raising an exception. No such invariant is desired for ordering, so default implementations of < and > are not provided in Python 3. Nice. This bit should definitely make it into the doc patch if not already in the docs. However, saying this should not preclude classes where this is not the case, e.g. IEEE-754 NANs. I would not like this wording (which otherwise is very nice) to be used in the future to force reflexivity on object equality. https://en.wikipedia.org/wiki/Reflexiverelation To try to cut off arguments: - Yes, it is fine to have the default implementation of eq assume reflexivity. - Yes, it is fine for standard library containers (lists, dicts, etc.) to assume reflexivity of their items. - I'm fully aware that some people think the non-reflexivity of NANs is logically nonsensical and a mistake. I do not agree with them. - I'm not looking to change anything here, the current behaviour is fine, I just want to ensure that an otherwise admirable doc change does not get interpreted in the future in a way that prevents classes from defining eq to be non-reflexive.

+1



More information about the Python-Dev mailing list