-
Notifications
You must be signed in to change notification settings - Fork 245
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
Comments
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
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. 😸 |
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. |
@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. |
Is there any progress on this? It seems like the fix in question is still in a draft state and needs to be updated. |
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.
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. |
Duplicate of #4541 |
This issue is now closed. Comments on closed issues are hard for our team to see. |
🐛 Bug Report
Affected Languages
TypeScript
orJavascript
Python
Java
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:
#4541
Proposed solution
Treating all parameter name changes as breaking changes. Enforce the same parameter names in interface implementations.
The text was updated successfully, but these errors were encountered: