Skip to content

Commit

Permalink
docs(database): add docstrings to DictDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
hearot committed Jun 11, 2020
1 parent 318172a commit 7776cdc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
- Add docstrings to `BaseHandler` ([455a0a94977c1652b445b623df561f9606a0615e](https://github.com/hearot/pyrubrum/commit/455a0a94977c1652b445b623df561f9606a0615e))
- Add docstrings to `BaseMenu` ([3a7ad4e3b23bfb85a9faa8c3c056e76abb87b771](https://github.com/hearot/pyrubrum/commit/3a7ad4e3b23bfb85a9faa8c3c056e76abb87b771))
- Add docstrings to `Button` ([73a0848e8bd7159599d2023d86249f192fde65b4](https://github.com/hearot/pyrubrum/commit/73a0848e8bd7159599d2023d86249f192fde65b4))
- Add docstrings to `DictDatabase`
- Add docstrings to all the database exceptions ([0e561554d9d37ef755202cb7ef2905aadbd84700](https://github.com/hearot/pyrubrum/commit/0e561554d9d37ef755202cb7ef2905aadbd84700))
- Add issue templates ([64c006258e373a97d0a9f83318af02c4310b585b](https://github.com/hearot/pyrubrum/commit/64c006258e373a97d0a9f83318af02c4310b585b))
- Add the official pronunciation for Pyrubrum ([b6d1fe8e01f79007338cd4a6dfe409c406c12cba](https://github.com/hearot/pyrubrum/commit/b6d1fe8e01f79007338cd4a6dfe409c406c12cba))
- Create the changelog of the current release separately
- Create the changelog of the current release separately ([318172a986e666ac4abf6f7a4480922cb135e734](https://github.com/hearot/pyrubrum/commit/318172a986e666ac4abf6f7a4480922cb135e734))
- Delete duplicate issue templates ([10cba65c31a5c3556b39cc328d097b62dfbd5e1b](https://github.com/hearot/pyrubrum/commit/10cba65c31a5c3556b39cc328d097b62dfbd5e1b))
- Make relative clauses more formal ([6b0d84effd65838668b3ba070a677d03ce016581](https://github.com/hearot/pyrubrum/commit/6b0d84effd65838668b3ba070a677d03ce016581))
- Stop using `typing.NewType` and use aliases instead ([600191f337178baf21ea5ffe3e9caaa19dbf22e0](https://github.com/hearot/pyrubrum/commit/600191f337178baf21ea5ffe3e9caaa19dbf22e0))
Expand Down
3 changes: 2 additions & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
- Add docstrings to `BaseHandler` ([455a0a94977c1652b445b623df561f9606a0615e](https://github.com/hearot/pyrubrum/commit/455a0a94977c1652b445b623df561f9606a0615e))
- Add docstrings to `BaseMenu` ([3a7ad4e3b23bfb85a9faa8c3c056e76abb87b771](https://github.com/hearot/pyrubrum/commit/3a7ad4e3b23bfb85a9faa8c3c056e76abb87b771))
- Add docstrings to `Button` ([73a0848e8bd7159599d2023d86249f192fde65b4](https://github.com/hearot/pyrubrum/commit/73a0848e8bd7159599d2023d86249f192fde65b4))
- Add docstrings to `DictDatabase`
- Add docstrings to all the database exceptions ([0e561554d9d37ef755202cb7ef2905aadbd84700](https://github.com/hearot/pyrubrum/commit/0e561554d9d37ef755202cb7ef2905aadbd84700))
- Add issue templates ([64c006258e373a97d0a9f83318af02c4310b585b](https://github.com/hearot/pyrubrum/commit/64c006258e373a97d0a9f83318af02c4310b585b))
- Add the official pronunciation for Pyrubrum ([b6d1fe8e01f79007338cd4a6dfe409c406c12cba](https://github.com/hearot/pyrubrum/commit/b6d1fe8e01f79007338cd4a6dfe409c406c12cba))
- Create the changelog of the current release separately
- Create the changelog of the current release separately ([318172a986e666ac4abf6f7a4480922cb135e734](https://github.com/hearot/pyrubrum/commit/318172a986e666ac4abf6f7a4480922cb135e734))
- Delete duplicate issue templates ([10cba65c31a5c3556b39cc328d097b62dfbd5e1b](https://github.com/hearot/pyrubrum/commit/10cba65c31a5c3556b39cc328d097b62dfbd5e1b))
- Make relative clauses more formal ([6b0d84effd65838668b3ba070a677d03ce016581](https://github.com/hearot/pyrubrum/commit/6b0d84effd65838668b3ba070a677d03ce016581))
- Stop using `typing.NewType` and use aliases instead ([600191f337178baf21ea5ffe3e9caaa19dbf22e0](https://github.com/hearot/pyrubrum/commit/600191f337178baf21ea5ffe3e9caaa19dbf22e0))
Expand Down
51 changes: 51 additions & 0 deletions pyrubrum/database/dict_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,64 @@


class DictDatabase(dict, BaseDatabase):
"""A reduced Implementation of a database using a dictionary, without the
assignment of an expire to a key whenever one is added to the database.
Warning:
It not recommended to use this in production, as it does not implement
expires, while other implementations, such as `RedisDatabase`, does.
In addition, any stored data will be erased as soon as the program
stops executing.
This implementation might be useful only in development and testing
mode.
"""

def get(self, key: str) -> Optional[str]:
"""Get the value which is stored with a certain key inside the database,
if any. Otherwise, it will just return ``None``.
This method will query the key using `dict.get`, which automatically
returns ``None`` if the key has not been found.
Args:
key (str): The key you are retrieving the value of from the
dictionary.
Returns:
Optional[str]: The value which is associated to the key in the
dictionary, if any. Otherwise, it is set to be ``None``.
"""
return dict.get(self, key)

def set(self, key: str, value: str, expire: Expire = None):
"""Assign a value to a certain key inside the database. Note that this
implementation ignores the setting of any expires.
This method will assign the provided value to the key using
`dict.update`.
Args:
key (str): The key you are adding or updating the value of.
value (str): The value which is being assigned to the key.
expire (Expire): The expire in seconds or as a `timedelta` object.
It gets ignored by this implementation. Defaults to ``None``.
"""

self.update({key: value})

def delete(self, key: str):
"""Delete a certain key from the database, together with its stored value.
This method will delete the provided key from the database using
`dict.pop`.
Args:
key (str): The key which is being deleted from the database,
together with its linked data.
Raises:
DeleteError: If no key was found.
"""
try:
self.pop(key)
except KeyError:
Expand Down

0 comments on commit 7776cdc

Please sign in to comment.