From e16b6cb148d9fe6599ec8ce4b2803f0aed3a1d6b Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 30 Sep 2025 14:00:09 +0200 Subject: [fix] JSON format: serialization of the result-types The ``JSONEncoder`` (``format="json"``) must perform a conversion to the built-in types for the ``msgspec.Struct``:: if isinstance(o, msgspec.Struct): return msgspec.to_builtins(o) The result types are already of type ``msgspec.Struct``, so they can be converted into built-in types. The field types (in the result type) that were not yet of type ``msgspec.Struct`` have been converted to:: searx.weather.GeoLocation@dataclass -> msgspec.Struct searx.weather.DateTime -> msgspec.Struct searx.weather.Temperature -> msgspec.Struct searx.weather.PressureUnits -> msgspec.Struct searx.weather.WindSpeed -> msgspec.Struct searx.weather.RelativeHumidity -> msgspec.Struct searx.weather.Compass -> msgspec.Struct BTW: Wherever it seemed sensible, the typing was also modernized in the modified files. Closes: https://github.com/searxng/searxng/issues/5250 Signed-off-by: Markus Heiser --- searx/plugins/time_zone.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'searx/plugins/time_zone.py') diff --git a/searx/plugins/time_zone.py b/searx/plugins/time_zone.py index f54a9ce6c..9239a3fbc 100644 --- a/searx/plugins/time_zone.py +++ b/searx/plugins/time_zone.py @@ -1,12 +1,11 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring -from __future__ import annotations import typing as t import datetime -from flask_babel import gettext # type: ignore +from flask_babel import gettext from searx.result_types import EngineResults from searx.weather import DateTime, GeoLocation @@ -53,13 +52,13 @@ class SXNGPlugin(Plugin): search_term = " ".join(query_parts).strip() if not search_term: - date_time = DateTime(time=datetime.datetime.now()) + date_time = DateTime(datetime.datetime.now()) results.add(results.types.Answer(answer=date_time.l10n())) return results geo = GeoLocation.by_query(search_term=search_term) if geo: - date_time = DateTime(time=datetime.datetime.now(tz=geo.zoneinfo)) + date_time = DateTime(datetime.datetime.now(tz=geo.zoneinfo)) tz_name = geo.timezone.replace('_', ' ') results.add( results.types.Answer( -- cgit v1.2.3