mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Ensure the set object description is reproducible.
Whilst working on the Reproducible Builds effort [0], we noticed
that sphinx could generate output that is not reproducible.
In particular, the rendering of `set` objects in default arguments
and elsewhere is currently non-determinstic. For example:
class A_Class(object):
a_set = {'a', 'b', 'c'}
Might be rendered as any of:
{'a', 'b', 'c'}
{'a', 'c', 'b'}
{'b', 'a', 'c'}
{'b', 'c', 'a'}
{'c', 'a', 'b'}
{'c', 'b', 'a'}
Patch attached that sorts the contents of sets whilst rendering.
This is parallel to the `dict` key sorting.
This was originally filed in Debian as #895553 [1].
[0] https://reproducible-builds.org/
[1] https://bugs.debian.org/895553
Signed-off-by: Chris Lamb <lamby@debian.org>
This commit is contained in:
@@ -346,6 +346,24 @@ def test_dictionary_sorting():
|
||||
assert description == "{'a': 1, 'b': 4, 'c': 3, 'd': 2}"
|
||||
|
||||
|
||||
def test_set_sorting():
|
||||
set_ = set("gfedcba")
|
||||
description = inspect.object_description(set_)
|
||||
if PY3:
|
||||
assert description == "{'a', 'b', 'c', 'd', 'e', 'f', 'g'}"
|
||||
else:
|
||||
assert description == "set(['a', 'b', 'c', 'd', 'e', 'f', 'g'])"
|
||||
|
||||
|
||||
def test_set_sorting_fallback():
|
||||
set_ = set((None, 1))
|
||||
description = inspect.object_description(set_)
|
||||
if PY3:
|
||||
assert description in ("{1, None}", "{None, 1}")
|
||||
else:
|
||||
assert description in ("set([1, None])", "set([None, 1])")
|
||||
|
||||
|
||||
def test_dict_customtype():
|
||||
class CustomType(object):
|
||||
def __init__(self, value):
|
||||
|
||||
Reference in New Issue
Block a user