-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[mod] addition of various type hints / tbc #5147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70a329c to
bab5dfd
Compare
1199f08 to
cdf80ed
Compare
- 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
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
cdf80ed to
2cfa284
Compare
Member
Author
|
FYI: This PR modifies a lot of files and therefore has high conflict potential .. further force pushes (like the last ones) are just to solve conflicts with current master branch. |
Member
Author
|
@inetol I'm very sorry, I have seen to late, that you had self-requested a review for this PR. Sadly matrix.org is down at this time I can't connect you that way. |
return42
added a commit
to return42/searxng
that referenced
this pull request
Sep 14, 2025
Continuation of searxng#5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [searxng#5147] searxng#5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
return42
added a commit
to return42/searxng
that referenced
this pull request
Sep 15, 2025
Continuation of searxng#5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [searxng#5147] searxng#5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
return42
added a commit
to return42/searxng
that referenced
this pull request
Sep 15, 2025
Continuation of searxng#5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [searxng#5147] searxng#5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
.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
These changes collectively enhance code maintainability, ensure better compatibility with type checkers and development tools, and improve the overall robustness of the project.
To avoid further complicating static typing due to the quirks that still exist in Python 3.9, it was also necessary to remove Python 3.9 from the support matrix. This PR is based on:
This is intended to form a first basis for the typification of our source code. Much more will be required, but I already mentioned it in PR-5075:
The changes in this PR-5147 are also designed in this sense.
Some people might think, what could be so difficult about retroactively typing code? If you work with static types in a project from the beginning, it is still easy, but if you retroactively typing the code there are some challenges.
Basically, you have to re-engineer the code to find the correct types. Wich is not feasible with reasonable effort for modules such as searx.network or searx.metrics. Here, one should consider whether these modules might be replaced by new modules in the future (network, for example, based on curl impoersonate / metrics replaced by container classes).
However, there will always be a lot of code in SearXNG that cannot be (reasonably) typed; for example, the JSON and DOM trees that are examined by the engines. Requirements like pygments also have generic interfaces (classes) that make static type checking impossible.
I/we are still at the very beginning. With a little more experience, we'll be able to provide (write down) somewhat helpful recommendations for action, and as the quality of our source code improves, we'll also be increasingly able to implement some criteria in CI as quality gates. But we still have a long way to go.
But all the complaining doesn't help, we have to start with the topic... this PR takes us a first step in the right direction and the benefits can already be felt with the merge of this PR in the developers' IDEs.
We use basedpyright, which can be easily installed via pipx, for example:
Its recommended to have a look at the following links: