Integrate from __future__ import annotations
#4643
Merged
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.
A conservative implementation of integrating
from __future__ import annotations
in the codebase. Updates all instances where type hints could utilize new syntax, utilizing newly added Ruff rules to find & adjust said instances. The resulting type-hints are much cleaner, even granting functionality which otherwise require 3.9 or 3.10 as their minimum Python version:As a result of this new implementation, the hacky workarounds for forward-declaring types will no longer be necessary. Namely,
sctyping.py
is no longer necessary & has been removed. Instead, one should usefrom typing import TYPE_CHECKING
& resolve imports like any other.There's a more involved alternative of this PR that adds
from __future__ import annotations
as a required import instead, making it appear on ALL scripts in the codebase. While it's arguably a "better" option, it would also create significantly more noise in the changelog. If this approach were to be taken, it'd have to be part of a wider refactor.Contributor Checklist:
CHANGES.txt
andRELEASE.txt
(and read theREADME.rst
).