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/brave.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/brave.py')
| -rw-r--r-- | searx/engines/brave.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/searx/engines/brave.py b/searx/engines/brave.py index fbbd43c4f..c1148b889 100644 --- a/searx/engines/brave.py +++ b/searx/engines/brave.py @@ -117,7 +117,7 @@ Implementations """ -from typing import Any, TYPE_CHECKING +import typing as t from urllib.parse import ( urlencode, @@ -139,13 +139,7 @@ from searx.utils import ( ) from searx.enginelib.traits import EngineTraits from searx.result_types import EngineResults - -if TYPE_CHECKING: - import logging - - logger: logging.Logger - -traits: EngineTraits +from searx.extended_types import SXNG_Response about = { "website": 'https://search.brave.com/', @@ -158,17 +152,19 @@ about = { base_url = "https://search.brave.com/" categories = [] -brave_category = 'search' -Goggles = Any +brave_category: t.Literal["search", "videos", "images", "news", "goggles"] = 'search' """Brave supports common web-search, videos, images, news, and goggles search. - ``search``: Common WEB search - ``videos``: search for videos - ``images``: search for images - ``news``: search for news -- ``goggles``: Common WEB search with custom rules +- ``goggles``: Common WEB search with custom rules, requires a :py:obj:`Goggles` URL. """ +Goggles: str = "" +"""This should be a URL ending in ``.goggle``""" + brave_spellcheck = False """Brave supports some kind of spell checking. When activated, Brave tries to fix typos, e.g. it searches for ``food`` when the user queries for ``fooh``. In @@ -192,7 +188,7 @@ time_range_support = False """Brave only supports time-range in :py:obj:`brave_category` ``search`` (UI category All) and in the goggles category.""" -time_range_map = { +time_range_map: dict[str, str] = { 'day': 'pd', 'week': 'pw', 'month': 'pm', @@ -200,12 +196,12 @@ time_range_map = { } -def request(query, params): +def request(query: str, params: dict[str, t.Any]) -> None: # Don't accept br encoding / see https://github.com/searxng/searxng/pull/1787 params['headers']['Accept-Encoding'] = 'gzip, deflate' - args = { + args: dict[str, t.Any] = { 'q': query, 'source': 'web', } @@ -254,7 +250,7 @@ def _extract_published_date(published_date_raw): return None -def response(resp) -> EngineResults: +def response(resp: SXNG_Response) -> EngineResults: if brave_category in ('search', 'goggles'): return _parse_search(resp) |