Skip to content

Commit

Permalink
Allow a user to iterate through ctx.options (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
parafoxia committed Sep 18, 2022
1 parent 13b36ca commit 15576b7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lightbulb/context/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class OptionsProxy:
options (Dict[:obj:`str`, Any]): Options to act as a proxy for.
"""

__slots__ = ("_options",)

def __init__(self, options: t.Dict[str, t.Any]) -> None:
self._options = options

Expand All @@ -51,6 +53,19 @@ def __getattr__(self, item: str) -> t.Any:
def __getitem__(self, item: str) -> t.Any:
return self._options.get(item)

def items(self) -> t.ItemsView[str, t.Any]:
"""
Iterates through the options and returns a series of key:value
pairs.
Returns:
ItemsView[:obj:`str`, Any]: The options items. This
is functionally similar to a list of tuples, where for
each tuple, the key is the option name, and the value is
the option value.
"""
return self._options.items()


class ResponseProxy:
"""
Expand Down

0 comments on commit 15576b7

Please sign in to comment.