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): parameter names shadow imported modules #3848

Merged
merged 1 commit into from
Nov 22, 2022

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 21, 2022

In certain cases, a function parameter may shadow an imported module name, resultin in run-time errors either during type-checking or during the type-cast that is performed before returning a kernel call's result.

This change adds a test case that covers this particular scenario in Python, and changes how foreign modules are imported so that an alias is always generated for those, removing the risk for collisions. It also moves the type-checking stubs out to the root of the module to remove the risk of more "runtime context" polluting the type evaluation.

Fixes aws/aws-cdk#22975


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

In certain cases, a function parameter may shadow an imported module
name, resultin in run-time errors either during type-checking or during
the type-cast that is performed before returning a kernel call's result.

This change adds a test case that covers this particular scenario in
Python, and changes how foreign modules are imported so that an alias
is always generated for those, removin the risk for collisions.

Fixes aws/aws-cdk#22975
@RomainMuller RomainMuller requested a review from a team November 21, 2022 18:06
@RomainMuller RomainMuller self-assigned this Nov 21, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 21, 2022
Copy link
Contributor

@MrArnoldPalmer MrArnoldPalmer left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@mergify
Copy link
Contributor

mergify bot commented Nov 22, 2022

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 Nov 22, 2022
@mergify
Copy link
Contributor

mergify bot commented Nov 22, 2022

Merging (with squash)...

@mergify mergify bot merged commit 8bac012 into main Nov 22, 2022
@mergify mergify bot deleted the rmuller/move-py-stubs-out-of-nesting branch November 22, 2022 17:19
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Nov 22, 2022
RomainMuller added a commit to DanielMSchmidt/jsii that referenced this pull request Dec 1, 2022
Added an integration test to verify parameters named `builtins` or `str`
do not shadow the relevant type names, which used to be problematic
until aws#3848 fixed the overarching issue, hoever the existing test only
covered the case where a parameter name shadowed an namespace/import.

Additionally, changes various `typing.Dict` keys that were mistakenly
spelled out as `str` to use `builtins.str` in order to improve overall
consistency in type declarations (see also aws#3866).

Co-authored-by: rmuller@amazon.fr
mergify bot pushed a commit that referenced this pull request Dec 1, 2022
Added an integration test to verify parameters named `builtins` or `str`
do not shadow the relevant type names, which used to be problematic
until #3848 fixed the overarching issue, hoever the existing test only
covered the case where a parameter name shadowed an namespace/import.
    
Additionally, changes various `typing.Dict` keys that were mistakenly
spelled out as `str` to use `builtins.str` in order to improve overall
consistency in type declarations (see also #3866).
    
Co-authored-by: rmuller@amazon.fr

---

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

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(ec2): Unexpected signature change for IVolume.grantAttachVolumeByResourceTag
2 participants