refactor(typing): use PEP 604 syntax for Optional annotations (UP045) - #8399
Open
manshahH wants to merge 1 commit into
Open
refactor(typing): use PEP 604 syntax for Optional annotations (UP045)#8399manshahH wants to merge 1 commit into
manshahH wants to merge 1 commit into
Conversation
Convert Optional[X] to X | None across the codebase and remove the temporary UP045 ignore from ruff.toml, so the fix and the removal of the ignore land together. 283 of the 285 violations were handled by the ruff autofix. The two remaining cases in utilities/batch/types.py are runtime assignments rather than annotations, so they were converted by hand and verified to compare equal to their previous definitions. Union is left in place, since it belongs to UP007.
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
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
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.



Issue number: closes #8398
Summary
Clears the first of the four temporary pyupgrade ignores in
ruff.toml, following the one rule per PR plan @leandrodamascena outlined in #8047.Optional[X]becomesX | Noneacross the repository, and"UP045"is removed fromlint.ignoreso the rule is enforced from here on.Changes
aws_lambda_powertools, 25 inexamples, 15 intests, plusruff.tomlOptionalimports left unused by the conversion were removed, sinceF401flags themThe two manual cases. Both are in
aws_lambda_powertools/utilities/batch/types.py, whereOptional[...]sits in a runtime assignment rather than an annotation:Ruff correctly refuses to autofix these, because the expression is evaluated at import time and a rewrite changes the object that actually gets built. I converted them by hand and checked the result against the previous definitions:
Unionis deliberately left in place there, since it belongs toUP007. Removing it here would blur the one rule per PR split.Docstrings. Twenty parameter descriptions and section comments inside files this PR already touches still referred to
Optional[...]while the code below them had changed, so they were brought in line. Files not otherwise modified by this PR were left alone.User experience
No user facing change. This is internal typing syntax only, and the runtime behaviour of every converted annotation and alias is unchanged.
For contributors,
UP045is now enforced, so the olderOptional[X]spelling gets caught bymake lintinstead of being silently accepted.Verification
ruff checkpasses withUP045enforcedruff format --check: 1310 files already formatteddevelopmypy aws_lambda_powertools examples: same error count before and after, no new errors introducedHappy to carry on with
UP007and thenUP035in the same shape once this one looks right.Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.