Skip to content

Commit

Permalink
add __contains__ and __call__
Browse files Browse the repository at this point in the history
  • Loading branch information
j042 committed Jan 29, 2024
1 parent 758eb49 commit 5eab90c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gustaf/helpers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ def __getitem__(self, key):
else:
raise KeyError(f"`{key}` is not stored for {type(self._helpee)}")

def __contains__(self, key):
"""Returns if saved data contains the given key.
Parameters
----------
key: str
Returns
-------
value
"""
return key in self._saved

def pop(self, key, default=None):
"""
Applied pop() to saved data
Expand Down
17 changes: 17 additions & 0 deletions gustaf/helpers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ def __getitem__(self, key):
else:
raise TypeError(f"Invalid key type for {type(self)}")

def __call__(self, **kwargs):
"""Alias to `update()`"""
self.update(**kwargs)

def __contains__(self, key):
"""Returns if current option contains given key.
Parameters
----------
key: str
Returns
-------
contains: bool
"""
return key in self._options

def get(self, key, default=None):
"""
Gets value from key and default. Similar to dict.get(),
Expand Down

0 comments on commit 5eab90c

Please sign in to comment.