Am Dienstag, 28. Januar 2020 00:41:55 UTC+1 schrieb Michael Orlitzky:
>
> The insertion order is part of the language as of python-3.7, and can't 
> be changed: 
>
> * https://mail.python.org/pipermail/python-dev/2017-December/151283.html 
> * https://docs.python.org/3.7/tutorial/datastructures.html#dictionaries 
>
> So while it sucks, I guess we should update all of the doctests to print 
> in that order. It was always a bad idea to rely on them being sorted, 
> and I don't think I agree with making the order part of the language, 
> but that's what we've got. 
>

While the order of dictionaries is insertion order now, functions in Sage 
or in libraries that return dictionaries usually do not make any promise 
about the order in which elements are inserted into the dictionary. Thus, 
when doctesting such a function, the order of the result is not specified 
and might easily change by a seemingly unrelated change in our code base. 
This is not a huge problem, as we can update any failing doctests, but we 
could also make the doctests more robust in the first place, by sorting the 
output.



>From the different options mentioned here, my preferred choices are

2c) `pretty_print(D, sort=True)` for clarity, or

2d) `dict(sorted(D.items()))` for simplicity, as this makes use of 
well-known functions and does not require any other changes.

As Nils explained, for 2c (and even independently) it would make sense to 
change the default display mode from `None` to `plain` in the command line, 
but this would lead to a small dichotomy between the command line and the 
notebook, which is why I am slightly hesistant about this. It would make it 
a bit more difficult to doctest the notebook behavior. Therefore, I am 
leaning toward 2d, which should be an uncontroversial change and is similar 
to the `sorted(...)` idiom already used in the doctests.
 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/01d7ee8c-7e7c-4426-be3f-24d9161bd58f%40googlegroups.com.

Reply via email to