From 21d0428cf2dd5c1e3f8ae1702494bbaedf90c2fc Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 10 Oct 2025 16:14:29 +0200 Subject: [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 --- searx/__init__.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'searx/__init__.py') 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(): -- cgit v1.2.3