[Python-ideas] Fwd: Why do equality tests between OrderedDict keys/values views behave not as expected?

Sven R. Kunze srkunze at mail.de
Wed Jan 20 13:39:09 EST 2016


Documentation is a very good idea.

Maybe, even raise an error when comparing values.

Best,
Sven

On 20.01.2016 12:13, Alexandre Figura wrote:
> If we put technical considerations aside, maybe we should just ask to 
> ourselves what behavior do we expect when doing equality tests between 
> ordered dictionaries. As a reminder:
>
> >>> xy = OrderedDict([('x', None), ('y', None)])
> >>> yx = OrderedDict([('y', None), ('x', None)])
> >>> xy == yx
> False
> >>> xy.items() == yx.items()
> True
> >>> xy.keys() == yx.keys()
> True
> >>> xy.values() == yx.values()
> False
>
> So, it appears that:
> 1. equality tests between odict_values use objects identity and not 
> equality,
> 2. equality tests between odict_keys do not respect order.
>
> If it is not technically possible to change the current 
> implementation, maybe all we can do is just add a warning about 
> current behavior in the documentation?
>
> On Mon, Jan 11, 2016 at 4:17 AM, Guido van Rossum <guido at python.org 
> <mailto:guido at python.org>> wrote:
>
>     Seems like we dropped the ball... Is there any action item here?
>
>     -- 
>     --Guido van Rossum (python.org/~guido <http://python.org/%7Eguido>)
>
>     _______________________________________________
>     Python-ideas mailing list
>     Python-ideas at python.org <mailto:Python-ideas at python.org>
>     https://mail.python.org/mailman/listinfo/python-ideas
>     Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160120/f14e5b9d/attachment.html>


More information about the Python-ideas mailing list