diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-07-31 13:45:16 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-08-19 12:04:35 +0200 |
| commit | 25647c20d1904840d089892bb118390f46c66984 (patch) | |
| tree | a2db511a7444ea0504dbe83d484a556003d57e9b /searx | |
| parent | 9bb04e288ddda7d91fd6e2d87adc3bdaf01bd7c8 (diff) | |
[mod] switching from pyright to basedpyright (plus first rules)
pyrightconfig.json :
for the paths searx, searxng_extra and tests, individual rules were
defined (for example, in test fewer / different rules are needed than in the
searx package
searx/engines/__builtins__.pyi :
The builtin types that are added to the global namespace of a module by the
intended monkey patching of the engine modules / replaces the previous
filtering of the stdout using grep.
test.pyright_modified (utils/lib_sxng_test.sh) :
static type check of local modified files not yet commited
make test :
prerequisite 'test.pyright' has been replaced by 'test.pyright_modified'
searx/engines/__init__.py, searx/enginelib/__init__.py :
First, minimal typifications that were considered necessary.
Diffstat (limited to 'searx')
| -rw-r--r-- | searx/enginelib/__init__.py | 2 | ||||
| -rw-r--r-- | searx/engines/__builtins__.pyi | 43 | ||||
| -rw-r--r-- | searx/engines/__init__.py | 17 |
3 files changed, 52 insertions, 10 deletions
diff --git a/searx/enginelib/__init__.py b/searx/enginelib/__init__.py index 9cb49c0cd..3fa4edabb 100644 --- a/searx/enginelib/__init__.py +++ b/searx/enginelib/__init__.py @@ -252,7 +252,7 @@ class Engine: # pylint: disable=too-few-public-methods display_error_messages: bool """Display error messages on the web UI.""" - proxies: dict + proxies: dict[str, dict[str, str]] """Set proxies for a specific engine (YAML): .. code:: yaml diff --git a/searx/engines/__builtins__.pyi b/searx/engines/__builtins__.pyi new file mode 100644 index 000000000..c9c328b0c --- /dev/null +++ b/searx/engines/__builtins__.pyi @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""The builtin types that are added to the global namespace of a module by the +intended monkey patching of the engine modules. + +.. attention:: + + Monkey-patching modules is a practice from the past that shouldn't be + expanded upon. In the long run, there should be an engine class that can be + inherited. However, as long as this class doesn't exist, and as long as all + engine modules aren't converted to an engine class, these builtin types will + still be needed. +""" +from __future__ import annotations + +import logging + +logger: logging.Logger +supported_languages: str +language_aliases: str + +# from searx.engines.ENGINE_DEFAULT_ARGS +about: dict[str, dict[str, str | None | bool]] +categories: list[str] +disabled: bool +display_error_messages: bool +enable_http: bool +engine_type: str +inactive: bool +max_page: int +paging: int +safesearch: int +send_accept_language_header: bool +shortcut: str +time_range_support: int +timeout: int +tokens: list[str] +using_tor_proxy: bool + +# from searx.engines.check_engine_module +network: str + +# from searx.engines.update_attributes_for_tor +search_url: str diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index bcbdbe8aa..1138668dd 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -9,24 +9,26 @@ usage:: """ from __future__ import annotations +import typing as t import sys import copy from os.path import realpath, dirname -from typing import TYPE_CHECKING, Dict import types import inspect from searx import logger, settings from searx.utils import load_module -if TYPE_CHECKING: +if t.TYPE_CHECKING: from searx.enginelib import Engine logger = logger.getChild('engines') ENGINE_DIR = dirname(realpath(__file__)) -ENGINE_DEFAULT_ARGS = { + +# Defaults for the namespace of an engine module, see load_engine() +ENGINE_DEFAULT_ARGS: dict[str, int | str | list[t.Any] | dict[str, t.Any] | bool] = { # Common options in the engine module "engine_type": "online", "paging": False, @@ -49,11 +51,8 @@ ENGINE_DEFAULT_ARGS = { # set automatically when an engine does not have any tab category DEFAULT_CATEGORY = 'other' - -# Defaults for the namespace of an engine module, see :py:func:`load_engine` - -categories = {'general': []} -engines: Dict[str, Engine | types.ModuleType] = {} +categories: dict[str, list[str]] = {'general': []} +engines: dict[str, Engine | types.ModuleType] = {} engine_shortcuts = {} """Simple map of registered *shortcuts* to name of the engine (or ``None``). @@ -77,7 +76,7 @@ def check_engine_module(module: types.ModuleType): raise TypeError(msg) -def load_engine(engine_data: dict) -> 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>`` |