devctrl.utility.settings_db.SettingsDb#
- class SettingsDb(backend: SettingsBackend[K, S], settings_class: type[S])[source]#
Bases:
Generic[K,S]Database-like structure for storing SettingsClass instances.
Supports dictionary-like access with [] and ‘in’ operators. All entries are loaded from the backend on initialization. Use .save() to persist all changes to the backend.
- Parameters:
backend – Backend instance for persistence
settings_class – The SettingsClass subclass this DB stores
Methods
Get a settings instance by key, with optional default.
Message describing a valid key, shown to the user when an invalid key is entered.
Check if a key is allowed.
Return all (key, settings) pairs.
Return all keys.
Remove and return a value.
Save all entries to the backend.
Return all settings instances.
- __annotations__ = {'_data': 'dict[K, S]'}#
- classmethod __class_getitem__()#
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class
Foo, this is called when we doFoo[int]- there, withcls=Fooandparams=int.However, note that this method is also called when defining generic classes in the first place with
class Foo[T]: ....
- __contains__(key: K) bool[source]#
Check if a key exists.
- Parameters:
key – The key to check
- Returns:
True if the key exists, False otherwise
- __delitem__(key: K) None[source]#
Delete a settings instance by key.
- Parameters:
key – The key to delete
- Raises:
KeyError – If the key is not found
- __dict__ = mappingproxy({'__module__': 'devctrl.utility.settings_db', '__firstlineno__': 92, '__doc__': "Database-like structure for storing SettingsClass instances.\n\nSupports dictionary-like access with [] and 'in' operators.\nAll entries are loaded from the backend on initialization.\nUse .save() to persist all changes to the backend.\n\n:param backend: Backend instance for persistence\n:param settings_class: The SettingsClass subclass this DB stores\n", '__init__': <function SettingsDb.__init__>, '_load_from_backend': <function SettingsDb._load_from_backend>, 'save': <function SettingsDb.save>, '__getitem__': <function SettingsDb.__getitem__>, '__setitem__': <function SettingsDb.__setitem__>, '__delitem__': <function SettingsDb.__delitem__>, '__contains__': <function SettingsDb.__contains__>, '__iter__': <function SettingsDb.__iter__>, '__len__': <function SettingsDb.__len__>, 'keys': <function SettingsDb.keys>, 'values': <function SettingsDb.values>, 'items': <function SettingsDb.items>, 'get': <function SettingsDb.get>, 'pop': <function SettingsDb.pop>, 'get_valid_key_description': <classmethod(<function SettingsDb.get_valid_key_description>)>, 'is_key_allowed': <function SettingsDb.is_key_allowed>, '__repr__': <function SettingsDb.__repr__>, '__static_attributes__': ('_backend', '_data', '_settings_class', 'e_value_changed', 'e_value_removed'), '__orig_bases__': (typing.Generic[~K, ~S],), '__dict__': <attribute '__dict__' of 'SettingsDb' objects>, '__weakref__': <attribute '__weakref__' of 'SettingsDb' objects>, '__parameters__': (~K, ~S), '__annotations__': {'_data': 'dict[K, S]'}})#
- __firstlineno__ = 92#
- __getitem__(key: K) S[source]#
Get a settings instance by key.
- Parameters:
key – The key to look up
- Returns:
The settings instance
- Raises:
KeyError – If the key is not found
- __init__(backend: SettingsBackend[K, S], settings_class: type[S])[source]#
- classmethod __init_subclass__()#
Function to initialize subclasses.
- __module__ = 'devctrl.utility.settings_db'#
- __orig_bases__ = (typing.Generic[~K, ~S],)#
- __parameters__ = (~K, ~S)#
- __setitem__(key: K, value: S) None[source]#
Set a settings instance by key.
- Parameters:
key – The key to store under
value – The settings instance to store
- Raises:
TypeError – If value is not an instance of the expected SettingsClass
- __static_attributes__ = ('_backend', '_data', '_settings_class', 'e_value_changed', 'e_value_removed')#
- __weakref__#
list of weak references to the object
- _data: dict[K, S]#
- get(key: K, default: S | None = None) S | None[source]#
Get a settings instance by key, with optional default.
- Parameters:
key – The key to look up
default – Default value if key is not found
- Returns:
The settings instance, or default if not found
- classmethod get_valid_key_description() str[source]#
Message describing a valid key, shown to the user when an invalid key is entered.