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

docs: Mention Choice's Enum support in published docs, publish __init__ docs #161

Merged
merged 1 commit into from
Nov 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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