[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.
This commit is contained in:
Markus Heiser
2025-07-31 13:45:16 +02:00
committed by Markus Heiser
parent 9bb04e288d
commit 25647c20d1
8 changed files with 125 additions and 37 deletions

View File

@@ -51,25 +51,32 @@ test.pylint() {
}
test.pyright() {
# use this pyright test for local tests in development / it suppress
# warnings related to intentional monkey patching but gives good hints where
# we need to work on SearXNG's typification.
# For integration into your IDE (editor) use the basedpyright-langserver
# (LSP) installed by 'pipx basedpyright' and read:
#
# - https://docs.basedpyright.com/latest/installation/ides/
#
# The $REPO_ROOT/pyrightconfig.json uses the virtualenv found in
# $REPO_ROOT/local/py3 and create by a 'make pyenv'
build_msg TEST "[pyright/types] static type check of python sources"
node.env.dev
build_msg TEST "[basedpyright] static type check of python sources"
LANG=C pyenv.cmd basedpyright
# ignore exit value from basedpyright
# dump_return $?
return 0
}
build_msg TEST "[pyright/types] suppress warnings related to intentional monkey patching"
# We run Pyright in the virtual environment because pyright executes
# "python" to determine the Python version.
pyenv.cmd npx --no-install pyright -p pyrightconfig.json |
grep -E '\.py:[0-9]+:[0-9]+' |
grep -v '/engines/.*.py.* - warning: "logger" is not defined' |
grep -v '/plugins/.*.py.* - error: "logger" is not defined' |
grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' |
grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' |
grep -v '/engines/.*.py.* - warning: "categories" is not defined'
# ignore exit value from pyright
# dump_return ${PIPESTATUS[0]}
test.pyright_modified() {
build_msg TEST "[basedpyright] static type check of local modified files"
local pyrigth_files=()
readarray -t pyrigth_files < <(git status --porcelain | awk 'match($2,".py[i]*$") {print $2}')
if [ ${#pyrigth_files[@]} -eq 0 ]; then
echo "there are no locally modified python files that could be checked"
else
pyenv.cmd basedpyright "${pyrigth_files[@]}"
fi
# ignore exit value from basedpyright
# dump_return $?
return 0
}