[Python-Dev] Add __reversed__ methods for dict

Victor Stinner vstinner at redhat.com
Fri May 25 11:50:29 EDT 2018


It looks like an optimization, since you can already do something like
reversed(list(d)). Do you have benchmark numbers to see the benefit of
your change?

Even if reversed(list(d)) is slow, I'm not sure that it's worth it to
optimize it, since it's a rare usecase.

Victor

2018-05-24 14:55 GMT+02:00 Rémi Lapeyre <remi.lapeyre at vint.fr>:
>
> Hi,
>
> since dict keys are sorted by their insertion order since Python 3.6 and that
> it’s part of Python specs since 3.7 a proposal has been made in bpo-33462 to
> add the __reversed__ method to dict and dict views.
>
> Concerns have been raised in the comments that this feature may add too much
> bloat in the core interpreter and be harmful for other Python implementations.
>
> Given the different issues this change creates, I see three possibilities:
>
> 1. Accept the proposal has it is for dict and dict views, this would add about
> 300 lines and three new types in dictobject.c
>
> 2. Accept the proposal only for dict, this would add about 80 lines and one
> new type in dictobject.c while still being useful for some use cases
>
> 3. Drop the proposal as the whole, while having some use, reversed(dict(a=1, b=2))
> may not be very common and could be done using OrderedDict instead.
>
> What’s your stance on the issue ?
>
> Best regards,
> Rémi Lapeyre
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/vstinner%40redhat.com


More information about the Python-Dev mailing list