Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure default Set values are sorted for a reproducible build #535

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions traitlets/config/tests/test_configurable.py
Expand Up @@ -62,7 +62,9 @@ class Bar(Foo):
b = Unicode('gotit', help="The string b.").tag(config=False)
c = Float(help="The string c.").tag(config=True)
bset = Set([]).tag(config=True, multiplicity='+')
bset_values = Set([2,1,5]).tag(config=True, multiplicity='+')
bdict = Dict().tag(config=True, multiplicity='+')
bdict_values = Dict({1:'a','0':'b',5:'c'}).tag(config=True, multiplicity='+')

foo_help=u"""Foo(Configurable) options
-------------------------
Expand All @@ -83,8 +85,12 @@ class Bar(Foo):
Default: 0
--Bar.bdict <key-1>=<value-1>...
Default: {}
--Bar.bdict_values <key-1>=<value-1>...
Default: {1: 'a', '0': 'b', 5: 'c'}
--Bar.bset <set-item-1>...
Default: set()
--Bar.bset_values <set-item-1>...
Default: {1, 2, 5}
--Bar.c=<Float>
The string c.
Default: 0.0
Expand Down
7 changes: 7 additions & 0 deletions traitlets/traitlets.py
Expand Up @@ -2596,6 +2596,13 @@ def __init__(self, trait=None, default_value=None, minlen=0, maxlen=sys.maxsize,
"""
super(Set, self).__init__(trait, default_value, minlen, maxlen, **kwargs)

def default_value_repr(self):
# Ensure default value is sorted for a reproducible build
list_repr = repr(sorted(self.make_dynamic_default()))
if list_repr == '[]':
return 'set()'
return '{'+list_repr[1:-1]+'}'


class Tuple(Container):
"""An instance of a Python tuple."""
Expand Down