Skip to content

Core: Add type hints to aws/core.py #12617

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 1 commit into from
May 20, 2025
Merged

Core: Add type hints to aws/core.py #12617

merged 1 commit into from
May 20, 2025

Conversation

bblommers
Copy link
Contributor

@bblommers bblommers commented May 14, 2025

Motivation

The main reason for wanting types in this file is to make sure that context.account_id and context.region are always a string.

The handler chain will always set defaults for these variables, so we know they are set at runtime. Explicitly marking them as str makes it more obvious for service developers that they can trust the variables are set, and they don't have to manually assert that they are not None.

Changes

Most of the changes are self-explanatory, but the more spicier ones:

Installing botocore and rolo during linting

CircleCI now installs all typehint-dependencies during installation.

In our local venv we should have requirements-typehints installed, which means we have all the types - but the precommit-hook runs in an custom venv without those dependencies, so it will complain that they are missing. There are workarounds, for instance by creating a custom hook for mypy, but explicitly installing the dependencies we need during the pre-commit step is the easiest solution for now.

RequestContext API change

The request-parameter in RoloRequestContext is mandatory, and we do always supply it - so I've changed it to a mandatory parameter, and changed all the places where we create a RequestContext to add the request as an __init__-parameter.

Note that this class is never explicitly created in the AWS Pro repo, so we don't have to worry much about breaking changes. It is instantiated in Another emulator, but breaking changes are less important there, so I'll change that afterwards.

@bblommers bblommers added this to the Playground milestone May 14, 2025
@bblommers bblommers requested review from alexrashed and silv-io May 14, 2025 10:05
@bblommers bblommers added the semver: patch Non-breaking changes which can be included in patch releases label May 14, 2025
Copy link

github-actions bot commented May 14, 2025

S3 Image Test Results (AMD64 / ARM64)

  2 files    2 suites   9m 15s ⏱️
495 tests 445 ✅  50 💤 0 ❌
990 runs  890 ✅ 100 💤 0 ❌

Results for commit 412626b.

♻️ This comment has been updated with latest results.

@bblommers bblommers force-pushed the typing-aws-core branch 5 times, most recently from 3213dac to b0e5536 Compare May 14, 2025 11:54
Copy link

github-actions bot commented May 14, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 46m 2s ⏱️ +48s
4 452 tests ±0  4 067 ✅ ±0  385 💤 ±0  0 ❌ ±0 
4 454 runs  ±0  4 067 ✅ ±0  387 💤 ±0  0 ❌ ±0 

Results for commit 412626b. ± Comparison against base commit fa0bbcd.

♻️ This comment has been updated with latest results.

@bblommers bblommers marked this pull request as ready for review May 14, 2025 12:57
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! This is another great push for MyPy type enforcements!
From my perspective the changes to the typing are great, I would just love to have @k-a-il or @silv-io approve the change / verify that this would not break the GitHub workflow which is currently being implemented :)

- run:
name: Setup environment
command: |
make install-dev-types
Copy link
Member

Choose a reason for hiding this comment

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

@k-a-il @silv-io Now that the CircleCI pipeline is being migrated to GitHub Actions I think this would mean that we also have to change the make target here, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, would be great to add this in this PR.

On the other hand I think we should also be cautious with this switch because the typehint dependencies take waaaay longer to install in my experience (except when using uv :D)

Copy link
Member

Choose a reason for hiding this comment

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

Well, is this a blocker then? What does "waaaay longer" mean here?

Copy link
Member

Choose a reason for hiding this comment

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

@silv-io Could you please give some guidance here?

  • What does it mean to update the other action?
  • Where do we need to adjust the dependency installation for the type checking?
  • How can we properly verify that this PR covers this aspect, since it's already fully green?
  • What are the timing implications of this change you mentioned and what is acceptable for this PR to be merged?

Copy link
Member

@silv-io silv-io May 15, 2025

Choose a reason for hiding this comment

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

Yes :)

  • I'll add a suggestion in my review
  • After doing the suggested changes, the AWS / Build, Test, Push pipeline will run on this PR and we'll see if it works there as well. (We've still got some unrelated test failures around the Docker SDK there. These will not be blocking this PR)
  • I've checked the CircleCI Pipeline and it looks like it will add 30s of installation time. Seems like caching works a bit better here than on-device, so the impact is not as big. The trade-off is fine in this case.

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.

The changes in CircleCI look fine to me. The increase in installation time is not too big and completely justified by the extra functionality we're gaining.

Before merging this, I'd love to have these features in the GitHub Actions pipeline as well. To do this, we'd need to change these two actions to install the typehint dependency set instead of only the dev dependencies:

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
cache: 'pip'
cache-dependency-path: 'requirements-dev.txt'
- name: Install Community Dependencies
shell: bash
run: make install-dev

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
cache: 'pip'
cache-dependency-path: 'requirements-dev.txt'

Changing these should also trigger the new GHA pipeline. We can ignore single integration test failures on that pipeline since we've still got some issues there. The other steps, especially the linting, should still be green though.

/cc @k-a-il

- run:
name: Setup environment
command: |
make install-dev-types
Copy link
Member

@silv-io silv-io May 15, 2025

Choose a reason for hiding this comment

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

Yes :)

  • I'll add a suggestion in my review
  • After doing the suggested changes, the AWS / Build, Test, Push pipeline will run on this PR and we'll see if it works there as well. (We've still got some unrelated test failures around the Docker SDK there. These will not be blocking this PR)
  • I've checked the CircleCI Pipeline and it looks like it will add 30s of installation time. Seems like caching works a bit better here than on-device, so the impact is not as big. The trade-off is fine in this case.

@bblommers bblommers marked this pull request as draft May 15, 2025 09:16
@bblommers bblommers force-pushed the typing-aws-core branch 5 times, most recently from ce0a7e8 to bb82b54 Compare May 19, 2025 08:11
@bblommers
Copy link
Contributor Author

@silv-io Thanks for checking! I've also changed the GH pipelines to now install requirements-typehints.

I've also changed the pipeline to use the load-localstack-docker-from-artifacts/setup-tests-env actions from the current branch, instead of from master - otherwise we'd never be able to test changes to those actions.

@bblommers bblommers marked this pull request as ready for review May 19, 2025 09:26
@bblommers bblommers requested a review from silv-io May 19, 2025 09:26
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.

Nice, thank you for fixing paths to actions 👍 LGTM

@k-a-il
Copy link
Contributor

k-a-il commented May 19, 2025

I just merged my fix for the integration tests TestDockerClient and TestHooks. If you rebase your branch, the tests AWS / MA/MR tests / Run integration tests will pass.

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! Thank you for the changes

@bblommers
Copy link
Contributor Author

Appreciate the review and feedback @silv-io and @k-a-il 🙏

@bblommers bblommers merged commit 70b8643 into master May 20, 2025
82 of 84 checks passed
@bblommers bblommers deleted the typing-aws-core branch May 20, 2025 09:44
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