Skip to content

Conversation

@purcell
Copy link
Contributor

@purcell purcell commented Nov 6, 2025

Motivation

As of Python 3.9, common type annotations have changed, and the old ones (e.g. List, Optional, Union) generate deprecation warnings in some tools (pyright in my case). Our minimum Python version is 3.11, so it seems worthwhile to avoid those warnings, and I'm filing this PR as part of familiarising myself with the codebase.

Changes

This change updates the generation of scaffolded types to use the new names, and also adds default values in some cases, where further warnings were previously reported.

As a first step, the "logs" API has been regenerated, so that concrete changes can be inspected. It's not clear to me whether it is desirable or safe to actually update any generated modules yet, though.

Tests

Open question: would it be best to allow later gradual regeneration of scaffolds?

Related

@purcell purcell added semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Nov 6, 2025
@purcell
Copy link
Contributor Author

purcell commented Nov 6, 2025

@thrau I'd appreciate a read on how/whether to proceed with this, see questions above.

@thrau
Copy link
Member

thrau commented Nov 6, 2025

This makes a lot of sense to me! The APIs are not used in a context where we would need compatibility with older python versions. This makes the APIs more consistent with our other code styles, so 👍

@alexrashed anything to add?

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

S3 Image Test Results (AMD64 / ARM64)

    2 files    2 suites   7m 48s ⏱️
  533 tests 481 ✅  52 💤 0 ❌
1 066 runs  962 ✅ 104 💤 0 ❌

Results for commit df9a078.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Test Results - Preflight, Unit

22 259 tests   - 23   20 507 ✅  - 23   16m 12s ⏱️ -23s
     1 suites ± 0    1 752 💤 ± 0 
     1 files   ± 0        0 ❌ ± 0 

Results for commit 47cf9af. ± Comparison against base commit 447dd8e.

This pull request removes 23 tests.
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-copy_volumes]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-create_capacity_manager_data_export]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-create_ipam_prefix_list_resolver]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-create_ipam_prefix_list_resolver_target]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-delete_capacity_manager_data_export]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-delete_ipam_prefix_list_resolver]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-delete_ipam_prefix_list_resolver_target]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-describe_capacity_manager_data_exports]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-describe_capacity_reservation_topology]
tests.unit.aws.api.test_asf_providers ‑ test_provider_signatures[Ec2Provider-Ec2Api-describe_ipam_prefix_list_resolver_targets]
…

♻️ This comment has been updated with latest results.

@purcell
Copy link
Contributor Author

purcell commented Nov 6, 2025

But would it also make sense to run through all the APIs and regenerate them? Or is there a risk I'm not seeing? It doesn't seem like things are often regenerated.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   2h 1m 3s ⏱️ +2s
4 894 tests ±0  4 525 ✅ ±0  369 💤 ±0  0 ❌ ±0 
4 896 runs  ±0  4 525 ✅ ±0  371 💤 ±0  0 ❌ ±0 

Results for commit 47cf9af. ± Comparison against base commit 447dd8e.

♻️ This comment has been updated with latest results.

@alexrashed
Copy link
Member

But would it also make sense to run through all the APIs and regenerate them? Or is there a risk I'm not seeing? It doesn't seem like things are often regenerated.

That would definitely make sense! And in fact, they are regenerated every week by our "ASF Update Action", which results in PRs like this: #13283
You don't see a lot of updates though, because compared to the amount of operations there aren't many updates usually within a week and we really don't often update the actual code generation.
So from my perspective this change would be great! For the specific implementation right now however, it seems like there's still an issue as a unit test for the scaffold itself is failing on a compile error of some of the generated APIs.
Let me know if we should take a look at this together, happy to help!

@purcell purcell force-pushed the updated-scaffold-types branch from d1e6ce7 to 3b7a3a8 Compare November 6, 2025 14:19
@purcell
Copy link
Contributor Author

purcell commented Nov 6, 2025

Thand @alexrashed. Yeah, I'm looking at the compile errors.

@purcell purcell force-pushed the updated-scaffold-types branch from 3b7a3a8 to c41dd71 Compare November 6, 2025 17:50
@purcell
Copy link
Contributor Author

purcell commented Nov 6, 2025

Fixed now, and I also regenerated the module for S3, which was involved in the failure above.

Looking at the failures, there are interesting cases in the generated code that were possibly not correct even before this change. For example, in the s3 API:

Location = str

...

class PostResponse(TypedDict, total=False):
    StatusCode: None | GetObjectResponseStatusCode
    Location: None | Location
    LocationHeader: None | Location     # Here pyright sees a reference to PostResponse.Location, not the top-level Location type alias
    Bucket: None | BucketName
    Key: None | ObjectKey
    Expiration: None | Expiration
    ETag: None | ETag
    ETagHeader: None | ETag
    ChecksumCRC32: None | ChecksumCRC32
    ChecksumCRC32C: None | ChecksumCRC32C
    ChecksumCRC64NVME: None | ChecksumCRC64NVME
    ChecksumSHA1: None | ChecksumSHA1
    ChecksumSHA256: None | ChecksumSHA256
    ChecksumType: None | ChecksumType

@purcell
Copy link
Contributor Author

purcell commented Nov 6, 2025

If this looks acceptable, I expect the best plan would be to take out the generated changes from this commit, and merge only the scaffold generator changes, so that the next auto-update would cleanly update everything together.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Test Results (amd64) - Acceptance

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

Results for commit 47cf9af. ± Comparison against base commit 447dd8e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files  ±0      5 suites  ±0   2h 36m 30s ⏱️ - 2m 53s
5 268 tests ±0  4 739 ✅ ±0  529 💤 ±0  0 ❌ ±0 
5 274 runs  ±0  4 739 ✅ ±0  535 💤 ±0  0 ❌ ±0 

Results for commit 47cf9af. ± Comparison against base commit 447dd8e.

♻️ 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.

This is looking great! I guess the failing tests are not associated to the changes here, and will most likely be fixed by a rebase.
Concerning the approach, I don't have a strong opinion, but basically we can (a) either combine the update with the changes here maybe in separate commits (+ create a separate PR in our downstream repo to update the generated code there as well), or (b) we just merge the changes to the code generation and let the automation update all the code.
In guess (a) is a bit cleaner because then the API changes aren't mixed with the updated code generation and we have an isolated CI execution for the changes in the generated code, but (b) is a bit simpler to execute on.
I'd just leave that to you! 😃

As of Python 3.9, common type annotations have changed, and the old
ones (e.g. List, Optional, Union) generate deprecation warnings in
some tools (pyright in my case).

This change updates the generation of scaffolded types to use the new
names, and also adds default values in some cases, where further
warnings were previously reported.
@purcell purcell force-pushed the updated-scaffold-types branch from c41dd71 to 47cf9af Compare November 7, 2025 10:06
@purcell
Copy link
Contributor Author

purcell commented Nov 7, 2025

I've fixed that nit, and separated the change into two commits: one for the generator change, and the other for the API regeneration. If the tests run through fine, I'll drop the latter and we can just merge the former, waiting for the weekly job to cleanly regenerate everything.

@purcell
Copy link
Contributor Author

purcell commented Nov 7, 2025

Tests are good. I'll remove the generated API update commit, and mark this ready for review.

@purcell purcell force-pushed the updated-scaffold-types branch from 47cf9af to df9a078 Compare November 7, 2025 11:25
@purcell purcell marked this pull request as ready for review November 7, 2025 11:26
@purcell purcell requested a review from thrau as a code owner November 7, 2025 11:26
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.

:shipit: 😛

@purcell purcell merged commit 37b23d0 into main Nov 7, 2025
22 checks passed
@purcell purcell deleted the updated-scaffold-types branch November 7, 2025 11:40
@giograno
Copy link
Member

giograno commented Nov 7, 2025

Awesome 🎉 We even might simplify some ruff settings we added with py-upgrade.

@purcell
Copy link
Contributor Author

purcell commented Nov 7, 2025

Yes, it looks like all those exclusion codes relate to annotations, so they shouldn't be necessary now.

purcell added a commit that referenced this pull request Nov 7, 2025
As of #13347, the type annotations in those modules are modern and
will not upset ruff.
@purcell
Copy link
Contributor Author

purcell commented Nov 7, 2025

Submitted a fix in #13355.

@alexrashed alexrashed mentioned this pull request Nov 10, 2025
purcell added a commit that referenced this pull request Nov 10, 2025
As of #13347, the type annotations in those modules are modern and
will not upset ruff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants