summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-01-17 07:54:37 +0100
committerMartin Fischer <martin@push-f.com>2022-01-17 11:18:17 +0100
commit1ed618222f17e205b684f6ef63cdaa470beb0dcb (patch)
tree81f124d8a05ccd1438b0d848945d6d283469e307 /searx/webapp.py
parent96ab5e57ff92aba4ab0fedeb4e5fbfa09e9fc2e2 (diff)
downloadsearxng-1ed618222f17e205b684f6ef63cdaa470beb0dcb.tar.gz
searxng-1ed618222f17e205b684f6ef63cdaa470beb0dcb.zip
[typing] add ExtendedRequest
webapp.py monkey-patches the Flask request global. This commit adds a type cast so that e.g. Pyright[1] doesn't show "Cannot access member" errors everywhere. [1]: https://github.com/microsoft/pyright
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 3df9f2876..905f53d1f 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -14,6 +14,8 @@ from datetime import datetime, timedelta
from timeit import default_timer
from html import escape
from io import StringIO
+import typing
+from typing import List, Dict
import urllib
from urllib.parse import urlencode
@@ -28,7 +30,6 @@ import flask
from flask import (
Flask,
- request,
render_template,
url_for,
Response,
@@ -89,7 +90,7 @@ from searx.utils import (
)
from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH
from searx.query import RawTextQuery
-from searx.plugins import plugins, initialize as plugin_initialize
+from searx.plugins import Plugin, plugins, initialize as plugin_initialize
from searx.plugins.oa_doi_rewrite import get_doi_resolver
from searx.preferences import (
Preferences,
@@ -224,6 +225,21 @@ exception_classname_to_text = {
_flask_babel_get_translations = flask_babel.get_translations
+class ExtendedRequest(flask.Request):
+ """This class is never initialized and only used for type checking."""
+
+ preferences: Preferences
+ errors: List[str]
+ user_plugins: List[Plugin]
+ form: Dict[str, str]
+ start_time: float
+ render_time: float
+ timings: List[dict]
+
+
+request = typing.cast(ExtendedRequest, flask.request)
+
+
def _get_translations():
if has_request_context() and request.form.get('use-translation') == 'oc':
babel_ext = flask_babel.current_app.extensions['babel']