Skip to content

Commit

Permalink
Merge pull request #161 from Jmennius/document-choice-better
Browse files Browse the repository at this point in the history
docs: Mention Choice's Enum support in published docs, publish __init__ docs
  • Loading branch information
sampsyo authored Nov 9, 2023
2 parents d8c649e + ff68ea7 commit 662dffa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions confuse/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def as_path(self):
def as_choice(self, choices):
"""Get the value from a list of choices. Equivalent to
`get(Choice(choices))`.
Sequences, dictionaries and :class:`Enum` types are supported,
see :class:`confuse.templates.Choice` for more details.
"""
return self.get(templates.Choice(choices))

Expand Down
3 changes: 3 additions & 0 deletions confuse/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ def convert(self, value, view):

class Choice(Template):
"""A template that permits values from a sequence of choices.
Sequences, dictionaries and :class:`Enum` types are supported,
see :meth:`__init__` for usage.
"""
def __init__(self, choices, default=REQUIRED):
"""Create a template that validates any of the values from the
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Templates
.. automodule:: confuse.templates
:members:
:private-members:
:special-members: __init__
:show-inheritance:

Utility
Expand Down

0 comments on commit 662dffa

Please sign in to comment.