summaryrefslogtreecommitdiff
path: root/searx/__init__.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2025-10-10 16:14:29 +0200
committerGitHub <noreply@github.com>2025-10-10 16:14:29 +0200
commit21d0428cf2dd5c1e3f8ae1702494bbaedf90c2fc (patch)
tree0e093ddfb89ce4ee7f9b58eb4f2fde9dcbedae17 /searx/__init__.py
parentf0dfe3cc0e2b9fce3e69a7525ab5fa073dbd459e (diff)
[mod] brand - partial migration of settings to msgspec.Struct (#5280)
The settings are currently an untyped key/value structure, whose types are dynamically built at runtime. The construction process of this structure is *hand-crafted*. In the long term, we want a static typing of this structure, based on a standard tool. The ``msgspec.Struct`` structures are suitable as a standard tool. This patch makes a first step towards static typing and implements the "brand" section using ``msgspec.Struct`` structures. BTW: searx/settings_defaults.py - ``git_url`` and ``git_branch`` had been removed in aee613d256, this is a leftover. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/__init__.py')
-rw-r--r--searx/__init__.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/searx/__init__.py b/searx/__init__.py
index 045affab0..5ee367d70 100644
--- a/searx/__init__.py
+++ b/searx/__init__.py
@@ -9,6 +9,7 @@ from os.path import dirname, abspath
import logging
+import msgspec
import searx.unixthreadname # pylint: disable=unused-import
# Debug
@@ -76,20 +77,22 @@ def get_setting(name: str, default: t.Any = _unset) -> t.Any:
settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
"""
- value: dict[str, t.Any] = settings
+ value = settings
for a in name.split('.'):
- if isinstance(value, dict):
- value = value.get(a, _unset)
+ if isinstance(value, msgspec.Struct):
+ value = getattr(value, a, _unset)
+ elif isinstance(value, dict):
+ value = value.get(a, _unset) # pyright: ignore
else:
- value = _unset # type: ignore
+ value = _unset
if value is _unset:
if default is _unset:
raise KeyError(name)
- value = default # type: ignore
+ value = default
break
- return value
+ return value # pyright: ignore
def _is_color_terminal():