diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-08-22 17:17:51 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-09-03 13:37:36 +0200 |
| commit | 57b9673efb1b4fd18a3ac15e26da642201e2cd33 (patch) | |
| tree | 79d3ecd365a1669a1109aa7e5dd3636bc1041d96 /searx/engines/__init__.py | |
| parent | 09500459feffa414dc7a0601bdb164464a8b0454 (diff) | |
[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 <markus.heiser@darmarit.de>
Format: reST
Diffstat (limited to 'searx/engines/__init__.py')
| -rw-r--r-- | searx/engines/__init__.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 1138668dd..839c10a5c 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -51,8 +51,8 @@ ENGINE_DEFAULT_ARGS: dict[str, int | str | list[t.Any] | dict[str, t.Any] | bool # set automatically when an engine does not have any tab category DEFAULT_CATEGORY = 'other' -categories: dict[str, list[str]] = {'general': []} -engines: dict[str, Engine | types.ModuleType] = {} +categories: "dict[str, list[Engine|types.ModuleType]]" = {'general': []} +engines: "dict[str, Engine | types.ModuleType]" = {} engine_shortcuts = {} """Simple map of registered *shortcuts* to name of the engine (or ``None``). @@ -76,7 +76,7 @@ def check_engine_module(module: types.ModuleType): raise TypeError(msg) -def load_engine(engine_data: dict[str, t.Any]) -> Engine | types.ModuleType | None: +def load_engine(engine_data: dict[str, t.Any]) -> "Engine | types.ModuleType | None": """Load engine from ``engine_data``. :param dict engine_data: Attributes from YAML ``settings:engines/<engine>`` @@ -151,7 +151,7 @@ def load_engine(engine_data: dict[str, t.Any]) -> Engine | types.ModuleType | No return engine -def set_loggers(engine, engine_name): +def set_loggers(engine: "Engine|types.ModuleType", engine_name: str): # set the logger for engine engine.logger = logger.getChild(engine_name) # the engine may have load some other engines @@ -170,7 +170,7 @@ def set_loggers(engine, engine_name): module.logger = logger.getChild(module_engine_name) # type: ignore -def update_engine_attributes(engine: Engine | types.ModuleType, engine_data): +def update_engine_attributes(engine: "Engine | types.ModuleType", engine_data: dict[str, t.Any]): # set engine attributes from engine_data for param_name, param_value in engine_data.items(): if param_name == 'categories': @@ -188,13 +188,13 @@ def update_engine_attributes(engine: Engine | types.ModuleType, engine_data): setattr(engine, arg_name, copy.deepcopy(arg_value)) -def update_attributes_for_tor(engine: Engine | types.ModuleType): +def update_attributes_for_tor(engine: "Engine | types.ModuleType"): if using_tor_proxy(engine) and hasattr(engine, 'onion_url'): engine.search_url = engine.onion_url + getattr(engine, 'search_path', '') # type: ignore engine.timeout += settings['outgoing'].get('extra_proxy_timeout', 0) # type: ignore -def is_missing_required_attributes(engine): +def is_missing_required_attributes(engine: "Engine | types.ModuleType"): """An attribute is required when its name doesn't start with ``_`` (underline). Required attributes must not be ``None``. @@ -207,12 +207,12 @@ def is_missing_required_attributes(engine): return missing -def using_tor_proxy(engine: Engine | types.ModuleType): +def using_tor_proxy(engine: "Engine | types.ModuleType"): """Return True if the engine configuration declares to use Tor.""" return settings['outgoing'].get('using_tor_proxy') or getattr(engine, 'using_tor_proxy', False) -def is_engine_active(engine: Engine | types.ModuleType): +def is_engine_active(engine: "Engine | types.ModuleType"): # check if engine is inactive if engine.inactive is True: return False @@ -224,7 +224,7 @@ def is_engine_active(engine: Engine | types.ModuleType): return True -def register_engine(engine: Engine | types.ModuleType): +def register_engine(engine: "Engine | types.ModuleType"): if engine.name in engines: logger.error('Engine config error: ambiguous name: {0}'.format(engine.name)) sys.exit(1) @@ -239,7 +239,7 @@ def register_engine(engine: Engine | types.ModuleType): categories.setdefault(category_name, []).append(engine) -def load_engines(engine_list): +def load_engines(engine_list: list[dict[str, t.Any]]): """usage: ``engine_list = settings['engines']``""" engines.clear() engine_shortcuts.clear() |