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/engines/duckduckgo_weather.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'searx/engines/duckduckgo_weather.py') diff --git a/searx/engines/duckduckgo_weather.py b/searx/engines/duckduckgo_weather.py index 9fad1e546..4d52effcd 100644 --- a/searx/engines/duckduckgo_weather.py +++ b/searx/engines/duckduckgo_weather.py @@ -76,12 +76,12 @@ def _weather_data(location: weather.GeoLocation, data: dict[str, t.Any]): return EngineResults.types.WeatherAnswer.Item( location=location, - temperature=weather.Temperature(unit="°C", value=data['temperature']), + temperature=weather.Temperature(val=data['temperature'], unit="°C"), condition=WEATHERKIT_TO_CONDITION[data["conditionCode"]], - feels_like=weather.Temperature(unit="°C", value=data['temperatureApparent']), + feels_like=weather.Temperature(val=data['temperatureApparent'], unit="°C"), wind_from=weather.Compass(data["windDirection"]), - wind_speed=weather.WindSpeed(data["windSpeed"], unit="mi/h"), - pressure=weather.Pressure(data["pressure"], unit="hPa"), + wind_speed=weather.WindSpeed(val=data["windSpeed"], unit="mi/h"), + pressure=weather.Pressure(val=data["pressure"], unit="hPa"), humidity=weather.RelativeHumidity(data["humidity"] * 100), cloud_cover=data["cloudCover"] * 100, ) -- cgit v1.2.3