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

Python: function overrides with different parameter names are incompatible #2927

Open
1 of 5 tasks
gshpychka opened this issue Jul 26, 2021 · 5 comments · May be fixed by #4197
Open
1 of 5 tasks

Python: function overrides with different parameter names are incompatible #2927

gshpychka opened this issue Jul 26, 2021 · 5 comments · May be fixed by #4197
Assignees
Labels
bug This issue is a bug. language/python Related to Python bindings p1

Comments

@gshpychka
Copy link

gshpychka commented Jul 26, 2021

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

What is the problem?

All generated Python code uses named parameters in function declarations. Python <3.8 doesn't have positional-only (unnamed) parameters at all.

As a result, any function overrides that change the parameter name make the subclass incompabitle with the parent.

Also, each change in a parameter name is a breaking change on the Python side.

Related issue on the AWS CDK side:

aws/aws-cdk#15584

Proposed solution

Treating all parameter name changes as breaking changes. Enforce the same parameter names in interface implementations.

@gshpychka gshpychka added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 26, 2021
@ryparker ryparker added the language/python Related to Python bindings label Jul 29, 2021
RomainMuller added a commit that referenced this issue Aug 9, 2021
In languages such as Python (<3.8) and Ruby, positional parameters can
be referred to using their names, making these names part of the
function signature. In order to avoid enforing parameter name
consistency on the TypeScript source, the `jsii` compiler will always
use the root declaration's parameter names when emitting the `.jsii`
assembly file.

Related #2927
@NGL321 NGL321 added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 7, 2022
@NGL321
Copy link
Contributor

NGL321 commented Jan 7, 2022

Hey @gshpychka,

It looks like a commit was made that might resolve this issue. Could you confirm this? If it did not resolve the issue we will continue to track this, otherwise we can close-out the related issues.

😸

@NGL321 NGL321 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 7, 2022
@github-actions
Copy link
Contributor

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 10, 2022
@gshpychka
Copy link
Author

@NGL321 I don't think I have enough experience to test this, but from my understanding, that commit is still in a draft PR and hasn't been merged.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 11, 2022
@sirrus233
Copy link
Contributor

Is there any progress on this? It seems like the fix in question is still in a draft state and needs to be updated.

RomainMuller added a commit that referenced this issue Jul 26, 2023
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.
@rafrafek
Copy link

rafrafek commented Aug 10, 2023

Enforce the same parameter names in interface implementations.

Please go with this proposed solution rather than the positional-only draft PR. We use Python because it is capable of programmer friendly things like keyword arguments.

Consider the example below where you want to feed cats:

program_the_robot(False, True)

What went wrong?

If you use keyword arguments it is much easier to spot the mistake:

program_the_robot(feed_cats=False, destroy_world=True)

As you can see keyword parameters can save the world and it is much harder to make a mistake when using them.

The positional-only draft PR is not a fix, it is a workaround trying to make Python less capable to match other languages so the error is ignored rather than fixed. It would be better to level other languages up rather than level Python down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. language/python Related to Python bindings p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants