SCons: Integrate annotations
as required import
#99180
Closed
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.
With 3.8 being the new minimum Python version, we can now utilize the extremely convenient
from __future__ import annotations
. Doing so adds functionality from PEP 5631, postponing the evaluation of type annotations away from define-time. In other words, a lot of hacky workarounds to setup type hints will no longer be necessary; the resulting syntax is much cleaner, even granting functionality which otherwise require 3.9 or 3.10 as their minimum Python version:Like the original PR, this adds
from __future__ import annotations
as a required import. While most files in our repo aren't using this functionality atm, it's still good practice for consistency & won't risk merge conflicts due to being at the very top of the import chain. To ensure that the aforementioned type-hint features are utilized, I've also addedUP006
2,UP007
3, andUP037
4 to the linter ruleset; because our repo never relied on the prior behavior, the first two "unsafe" rules have been marked as "safe" instead.Besides the above, exactly one other change was made: adding
version.py
to the list of files excluded from ruff evaluation. I could've instead added an exclusion for the required-import to that file, but I'd rather keep it entirely isolated as it functions as a metadata container. Additionally, as all these modifications are entirely isolated from runtime, no functional changes will be introduced by this PR.Footnotes
https://peps.python.org/pep-0563/ ↩
https://docs.astral.sh/ruff/rules/non-pep585-annotation/ ↩
https://docs.astral.sh/ruff/rules/non-pep604-annotation/ ↩
https://docs.astral.sh/ruff/rules/quoted-annotation/ ↩