From 57b9673efb1b4fd18a3ac15e26da642201e2cd33 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 22 Aug 2025 17:17:51 +0200 Subject: [mod] addition of various type hints / tbc - pyright configuration [1]_ - stub files: types-lxml [2]_ - addition of various type hints - enable use of new type system features on older Python versions [3]_ - ``.tool-versions`` - set python to lowest version we support (3.10.18) [4]_: Older versions typically lack some typing features found in newer Python versions. Therefore, for local type checking (before commit), it is necessary to use the older Python interpreter. .. [1] https://docs.basedpyright.com/v1.20.0/configuration/config-files/ .. [2] https://pypi.org/project/types-lxml/ .. [3] https://typing-extensions.readthedocs.io/en/latest/# .. [4] https://mise.jdx.dev/configuration.html#tool-versions Signed-off-by: Markus Heiser Format: reST --- searx/engines/demo_offline.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'searx/engines/demo_offline.py') diff --git a/searx/engines/demo_offline.py b/searx/engines/demo_offline.py index 6a3b8ddf7..13ec277f2 100644 --- a/searx/engines/demo_offline.py +++ b/searx/engines/demo_offline.py @@ -12,13 +12,14 @@ close to the implementation, its just a simple example. To get in use of this """ +import typing as t import json from searx.result_types import EngineResults from searx.enginelib import EngineCache -engine_type = 'offline' -categories = ['general'] +engine_type = "offline" +categories = ["general"] disabled = True timeout = 2.0 @@ -38,13 +39,13 @@ CACHE: EngineCache seconds.""" -def init(engine_settings): +def init(engine_settings: dict[str, t.Any]) -> None: """Initialization of the (offline) engine. The origin of this demo engine is a simple json string which is loaded in this example while the engine is initialized.""" global _my_offline_engine, CACHE # pylint: disable=global-statement - CACHE = EngineCache(engine_settings["name"]) # type:ignore + CACHE = EngineCache(engine_settings["name"]) _my_offline_engine = ( '[ {"value": "%s"}' @@ -55,20 +56,22 @@ def init(engine_settings): ) -def search(query, request_params) -> EngineResults: +def search(query: str, params: dict[str, t.Any]) -> EngineResults: """Query (offline) engine and return results. Assemble the list of results from your local engine. In this demo engine we ignore the 'query' term, usual you would pass the 'query' term to your local engine to filter out the results. """ res = EngineResults() - count = CACHE.get("count", 0) - for row in json.loads(_my_offline_engine): + count: int = CACHE.get("count", 0) + data_rows: list[dict[str, str]] = json.loads(_my_offline_engine) + + for row in data_rows: count += 1 kvmap = { 'query': query, - 'language': request_params['searxng_locale'], + 'language': params['searxng_locale'], 'value': row.get("value"), } res.add( -- cgit v1.2.3