-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
S3 Image Test Results (AMD64 / ARM64) 2 files 2 suites 9m 15s ⏱️ Results for commit 412626b. ♻️ This comment has been updated with latest results. |
3213dac
to
b0e5536
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- run: | ||
name: Setup environment | ||
command: | | ||
make install-dev-types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
localstack/.github/actions/setup-tests-env/action.yml
Lines 6 to 15 in 940aa0a
- 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 |
localstack/.github/actions/load-localstack-docker-from-artifacts/action.yml
Lines 16 to 21 in 549fd9b
- 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 |
There was a problem hiding this comment.
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.
b0e5536
to
e4a6c59
Compare
ce0a7e8
to
bb82b54
Compare
@silv-io Thanks for checking! I've also changed the GH pipelines to now install I've also changed the pipeline to use the |
There was a problem hiding this 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
I just merged my fix for the integration tests |
bb82b54
to
412626b
Compare
There was a problem hiding this 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
Motivation
The main reason for wanting types in this file is to make sure that
context.account_id
andcontext.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
androlo
during lintingCircleCI 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 formypy
, but explicitly installing the dependencies we need during thepre-commit
step is the easiest solution for now.RequestContext API change
The
request
-parameter inRoloRequestContext
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 aRequestContext
to add therequest
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.