Skip to content
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

fix(python): accept Sequence[T] for array parameters #2606

Merged
merged 5 commits into from
Mar 31, 2021

Conversation

RomainMuller
Copy link
Contributor

Instead of typing array (list) parameters as typing.List[T], using the
more flexible typing.Sequence[T] type, as recommended by the typing
package documentation for this use-case.

Using List[T] is inconvenient as it is invariant (ref), and requires
very intentional typing, which elads to boilerplate. Sequence[T] is
variant, which removes the need for boilerplate, as long as all items
in the sequence match the expected type.

This was reported in #4533


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Instead of typing array (list) parameters as `typing.List[T]`, using the
more flexible `typing.Sequence[T]` type, as recommended by the `typing`
package documentation for this use-case.

Using `List[T]` is inconvenient as it is invariant ([ref]), and requires
very intentional typing, which elads to boilerplate. `Sequence[T]` is
variant, which removes the need for boilerplate, as long as all items
in the sequence match the expected type.

[ref]: https://mypy.readthedocs.io/en/latest/common_issues.html#variance

This was reported in aws/aws-cdk#13203
@RomainMuller RomainMuller added language/python Related to Python bindings effort/small Small work item – less than a day of effort module/pacmak Issues affecting the `jsii-pacmak` module contribution/core This is a PR that came from AWS. labels Feb 24, 2021
@RomainMuller RomainMuller requested a review from a team February 24, 2021 16:28
@RomainMuller RomainMuller self-assigned this Feb 24, 2021
@@ -67,7 +67,7 @@ export function verifyGeneratedCodeFor(

expect({ [TREE]: checkTree(outDir) }).toMatchSnapshot('<outDir>/');

if (targetName !== TargetName.PYTHON) {
if (targetName !== TargetName.PYTHON || process.env.SKIP_MYPY_CHECK) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Mypy check adds between 40 and 100 seconds to the execution... Disabling it temporarily can help iterating much faster...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-6Jw05QLuWWwe
  • Commit ID: 09bdfcb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Mar 18, 2021

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Mar 18, 2021
@mergify
Copy link
Contributor

mergify bot commented Mar 18, 2021

Merging (with squash)...

@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2021

Merging (with squash)...

@mergify mergify bot merged commit b09d578 into main Mar 31, 2021
@mergify mergify bot deleted the rmuller/python-sequence-params branch March 31, 2021 10:23
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort language/python Related to Python bindings module/pacmak Issues affecting the `jsii-pacmak` module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants