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

feat(python): encode positional-only arguments in signatures #4197

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RomainMuller
Copy link
Contributor

Now that Python 3.7 reached end-of-life, and since Python 3.8 and greater have support for positional-only argument notation (any argument before a / delimiter may only be passed positionally), adjust code generation to leverage this feature in order to address issues where inheritance hierarchies would rename parameters, which is a non-issue in all languages but Python, where those could always be provided as keyword arguments before.

Fixes #2927

BREAKING CHANGE: the generated Python code now requires Python 3.8 or later and encodes positional arguments as positional-only, making keyword-style usage impossible. Users who used the keyword-style convention need to update their code to use the positional syntax instead.


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

Now that Python 3.7 reached end-of-life, and since Python 3.8 and
greater have support for positional-only argument notation (any argument
before a `/` delimiter may only be passed positionally), adjust code
generation to leverage this feature in order to address issues where
inheritance hierarchies would rename parameters, which is a non-issue in
all languages but Python, where those could always be provided as
keyword arguments before.

Fixes #2927

BREAKING CHANGE: the generated Python code now requires Python 3.8 or
later and encodes positional arguments as positional-only, making
keyword-style usage impossible. Users who used the keyword-style
convention need to update their code to use the positional syntax
instead.
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 26, 2023
# Conflicts:
#	packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap
@rafrafek
Copy link

where inheritance hierarchies would rename parameters

Is it necessary to rename them? I think it would be much better to keep keyword-style parameters and just use the parameter names consistently. For me it is a great benefit of Python and in many cases it would be even better to have keyword-style-only parameters other than positional-only.

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.

Python: function overrides with different parameter names are incompatible
2 participants