[Python-Dev] Should urlencode() sort the query parameters (if they come from a dict)?

Chris Angelico rosuav at gmail.com
Fri Aug 17 23:52:54 CEST 2012


On Sat, Aug 18, 2012 at 5:27 AM, Guido van Rossum <guido at python.org> wrote:
> I just fixed a unittest for some code used at Google that was
> comparing a url generated by urllib.encode() to a fixed string. The
> problem was caused by turning on PYTHONHASHSEED=1. Because of this,
> the code under test would generate a textually different URL each time
> the test was run, but the intention of the test was just to check that
> all the query parameters were present and equal to the expected
> values.
>
>
>         query = sorted(query.items())

Hmm. ISTM this is putting priority on the unit test above the
functionality of actual usage. Although on the other hand, sorting
parameters on a URL is nothing compared to the cost of network
traffic, so it's unlikely to be significant.

Chris Angelico


More information about the Python-Dev mailing list