Fix Settings().set() when setting new setting

Settings().set() would fail if we were trying to set a setting that did
not exist before. The reason is because before setting it would try to
get the previous value, but though direct key access, which would lead
to an exception.
This commit is contained in:
deeplow 2024-03-13 08:43:21 +00:00 committed by Alex Pyrgiotis
parent 5c86927269
commit ad16a0e471
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA

View file

@ -47,7 +47,10 @@ class Settings:
return self.settings[key] return self.settings[key]
def set(self, key: str, val: Any, autosave: bool = False) -> None: def set(self, key: str, val: Any, autosave: bool = False) -> None:
try:
old_val = self.get(key) old_val = self.get(key)
except KeyError:
old_val = None
self.settings[key] = val self.settings[key] = val
if autosave and val != old_val: if autosave and val != old_val:
self.save() self.save()