Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion confuse/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ def convert(self, value: object, view: ConfigView) -> T:
)

def __repr__(self) -> str:
return f"Choice({self.choices!r})"
args = [repr(self.choices)]

if self.default is not REQUIRED:
args.append(repr(self.default))

return f"Choice({', '.join(args)})"


class OneOf(Template[T]):
Expand Down
6 changes: 6 additions & 0 deletions test/test_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ def test_validate_bad_choice_in_dict(self):
with pytest.raises(confuse.ConfigValueError):
config["foo"].get(confuse.Choice({2: "two", 4: "four"}))

def test_repr_without_default(self):
assert repr(confuse.Choice([1, 2])) == "Choice([1, 2])"

def test_repr_includes_default(self):
assert repr(confuse.Choice([1, 2], 2)) == "Choice([1, 2], 2)"


class OneOfTest(unittest.TestCase):
def test_default_value(self):
Expand Down
Loading