Skip to content

Add pyupgrade rules to ruff #12953

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 8 commits into from
Aug 7, 2025
Merged

Add pyupgrade rules to ruff #12953

merged 8 commits into from
Aug 7, 2025

Conversation

giograno
Copy link
Member

@giograno giograno commented Aug 5, 2025

Motivation

This PR introduces Pyupgrade rules to our ruff configuration.
pyupgrade is a tool that automatically upgrades Python syntax to newer versions.

It introduces the same set of rules of pro#4989.

All the rules are automatically applied by the make format. They are also part of the pre-commit hook (after a make init-precommit).

Changes

  • Adding the PU rules to our ruff configuration. A few rules have been ignored as ruff does not yet provide a fix that guarantees the program's behavior to stay the same.
  • Setting py39 rules for two paths (localstack-core/localstack/utils/** and localstack-core/localstack/testing/pytest/**) as they are imported from the CLI test.
  • Ignore a few rules for the __init__ files. The rationale is the same as the companion PR.
  • Ignore the PU rules for `tests/aws/services/lambda_/functions/**. These modules are used by Lambda tests that run with a bunch of different runtimes.

I added a few self-contained commits to fix minor stuff I encountered, before committing the rules and all the formatting changes:

  • 18363fb that to convert all the typing.Union outside of type annotations (e.g., right-hand side of an assignment), as they can't be safely fixed by ruff.
  • fe94564 removing two instances of typing.ContextManager in favor of contextlib.AbstractContextManager. This is an unsafe fix at the moment.
  • I did find some type annotations with modules (json and datetime). I fixed them in 4631eca and 20dca66.
  • 6925499 to prevent the transformation of Optional[RLock] to RLock | None. In our Python version, RLock is not a type but a factory function. More info in the issue attached to the commit.
  • In 8f07b53 I specifically avoided fixes for types used as test input for convert_to_typed_dict.

@giograno giograno added this to the Playground milestone Aug 5, 2025
@giograno giograno self-assigned this Aug 5, 2025
@giograno giograno added the semver: patch Non-breaking changes which can be included in patch releases label Aug 5, 2025
Copy link

github-actions bot commented Aug 5, 2025

Test Results - Preflight, Unit

22 063 tests  ±0   20 329 ✅ ±0   6m 21s ⏱️ -2s
     1 suites ±0    1 734 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit f040dd5. ± Comparison against base commit e118075.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 5, 2025

S3 Image Test Results (AMD64 / ARM64)

    2 files    2 suites   8m 41s ⏱️
  515 tests 465 ✅  50 💤 0 ❌
1 030 runs  930 ✅ 100 💤 0 ❌

Results for commit f040dd5.

♻️ This comment has been updated with latest results.

@giograno giograno force-pushed the pyupgrade branch 11 times, most recently from 7cf76e9 to 97c5a6f Compare August 5, 2025 13:32
Copy link

github-actions bot commented Aug 5, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 8s ⏱️ -12s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit f040dd5. ± Comparison against base commit e118075.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 5, 2025

Test Results - Alternative Providers

1 078 tests   730 ✅  45m 8s ⏱️
    4 suites  348 💤
    4 files      0 ❌

Results for commit f040dd5.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 5, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   2h 20m 24s ⏱️
4 980 tests 4 393 ✅ 587 💤 0 ❌
4 986 runs  4 393 ✅ 593 💤 0 ❌

Results for commit f040dd5.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 5, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 40m 24s ⏱️ - 2m 48s
4 621 tests ±0  4 186 ✅ ±0  435 💤 ±0  0 ❌ ±0 
4 623 runs  ±0  4 186 ✅ ±0  437 💤 ±0  0 ❌ ±0 

Results for commit f040dd5. ± Comparison against base commit e118075.

♻️ This comment has been updated with latest results.

Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! From my perspective this is looking great! The changeset contains some very subtle changes which directly demonstrate why this kind of linting is a good idea to integrate! 💯
The only question that I still have is the same as for the PR in the downstream project:
How should we best merge this in order to cause the minimum amount of friction for other developers? Would be great if you could outline the different steps / the timeline and the implications (i.e. the steps contributors should take), before moving forward.

@giograno
Copy link
Member Author

giograno commented Aug 6, 2025

Thanks @alexrashed! My plan would be the following.

  • Give a shout-out today to the entire team. Everyone should be aware that they will need to rebase their open PRs after this gets merged. Otherwise, main could likely (temporarily) break.
  • Keeping an eye on this PR, keep rebasing and formatting all the new changes landing on main throughout he day.
  • Merge the PR at a time in the day when few engineers are working (e.g., late CET evening or early CET morning).

Copy link
Member

@silv-io silv-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@k-a-il k-a-il left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@giograno giograno force-pushed the pyupgrade branch 2 times, most recently from 202c93b to 4d3b20b Compare August 7, 2025 04:12
@giograno giograno merged commit f272f47 into main Aug 7, 2025
51 checks passed
@giograno giograno deleted the pyupgrade branch August 7, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants