Why is this needed?
Bumping the ruff target to py310 turned on a set of pyupgrade rules that were silenced rather than fixed. ruff.toml still carries temporary ignores for UP006, UP007, UP035 and UP045.
In #8047 @leandrodamascena proposed clearing these one rule per PR, safest first, with each PR removing its own ignore so the fix and the removal land together. This issue covers UP045 (Optional[X] to X | None), which was listed as one of the two safest to start with.
Current numbers on develop:
- 285 violations across 65 files (24 in
aws_lambda_powertools, 25 in examples, 15 in tests)
- 283 fixed automatically by the ruff autofix
- 2 need manual work, both in
aws_lambda_powertools/utilities/batch/types.py
The two manual cases are runtime assignments rather than annotations:
BatchTypeModels = Optional[Union[...]]
BatchSqsTypeModel = Optional[Type[SqsRecordModel]]
Ruff correctly refuses to autofix these, since rewriting them changes the object that is actually built at import time.
Opening this as a scoped issue so a PR has something to close. Happy to fold it into the umbrella issue instead if you would rather track all four rules in one place.
Which area does this relate to?
Static typing
Solution
- Apply the
UP045 autofix across the repository.
- Convert the two runtime assignments in
batch/types.py by hand, verifying the resulting object compares equal to the previous definition.
- Remove the
Optional imports left unused by the conversion, which F401 flags.
- Remove
"UP045" from lint.ignore in ruff.toml.
Union is deliberately left in place, since that belongs to UP007 and keeping it out preserves the one rule per PR split.
Acknowledgment
Why is this needed?
Bumping the ruff target to
py310turned on a set of pyupgrade rules that were silenced rather than fixed.ruff.tomlstill carries temporary ignores forUP006,UP007,UP035andUP045.In #8047 @leandrodamascena proposed clearing these one rule per PR, safest first, with each PR removing its own ignore so the fix and the removal land together. This issue covers
UP045(Optional[X]toX | None), which was listed as one of the two safest to start with.Current numbers on
develop:aws_lambda_powertools, 25 inexamples, 15 intests)aws_lambda_powertools/utilities/batch/types.pyThe two manual cases are runtime assignments rather than annotations:
Ruff correctly refuses to autofix these, since rewriting them changes the object that is actually built at import time.
Opening this as a scoped issue so a PR has something to close. Happy to fold it into the umbrella issue instead if you would rather track all four rules in one place.
Which area does this relate to?
Static typing
Solution
UP045autofix across the repository.batch/types.pyby hand, verifying the resulting object compares equal to the previous definition.Optionalimports left unused by the conversion, whichF401flags."UP045"fromlint.ignoreinruff.toml.Unionis deliberately left in place, since that belongs toUP007and keeping it out preserves the one rule per PR split.Acknowledgment