-
Notifications
You must be signed in to change notification settings - Fork 246
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
(@aws_cdk): Python: incompatible interface implementations due to differing function argument names #4541
Comments
@MrArnoldPalmer do you need any additional info regarding replicating the issue or the underlying causes? |
Hey @gshpychka, It looks like a commit was made in JSII 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. If it's merged, CDK releases would fail, since they don't satisfy the constraints. |
Commenting for updates. |
Thanks, I was on my phone. |
I'm typically closing jsii issues in this repo and tracking them in jsii instead, but this one looks like there's work to be done on both sides so I'm leaving this one open. |
FYI arg names in Protocol methods that start with double underscore won't cause name errors: seems that would allow implementations to name the arg however they want, though I guess it might complicate documentation and auto generating from the TS source (I am guessing) the docs above sound like it's specific to "callback protocols" but the convention seems to be generally respected e.g. changing this code in @jsii.member(jsii_name="secretValueFromJson")
def secret_value_from_json(self, __key: builtins.str) -> _SecretValue_3dd0ddae:
'''Interpret the secret as a JSON object and return a field's value from it as a ``SecretValue``.
:param key: -
'''
... |
transferring to jsii |
For future folks picking this up, there are several approaches for of solving this. On typescript sideIdeally, jsii libraries wouldn't have been allowed to create such inconsistencies. But now that they have, its impossible to change their source code because renaming positional arguments is a breaking change in python. So, solving this on the typescript side would only be possible by rolling out a new major version of the compiler and implementing aws/jsii-compiler#1320. Affected libraries would then pick up the new compiler, detect and fix these mismatches, and roll out a new major version of their own library. This is very disruptive. On jsii sideEnforce positional onlyThis implementation proposes we use a new Python 3.8 capability of marking arguments as positional only, and thus disallowing them to be invoked as keyword arguments. I'm not inclined to do this because many python users prefer invoking with keyword arguments always. It is also a breaking change so we won't be able to roll this out without a new major version. Argument renamingWe could have pacmak generate argnames that match the interface. This would satisfy type-checking. As for runtime, we will apply a new
Using double-underscore (
|
@iliapolo Sorry to post it here. But looks like
|
In Python prior to 3.8 (and in all the jsii-generated Python code), all function arguments are keyword arguments. In the TS source code, a lot of interface implementations override their interface's functions with different parameter names, which makes them incompatible with the interface in Python.
First of all, it causes typing errors (I'm using pyright).
More importantly, it makes these python classes incompatible with their interfaces.
To add to this, each change in a positional parameter name on the TS side is a breaking change on the Python side.
For example,
@aws_cdk.aws_lambda.Function
'sgrantInvoke
method usesgrantee
as its parameter name, whereasIFunction
usesidentity
. These end up being incompatible in Python.https://github.com/aws/aws-cdk/blob/b78a1bbf445743d96c8e4f54e7d2e7cac204342a/packages/%40aws-cdk/aws-lambda/lib/function-base.ts#L306
https://github.com/aws/aws-cdk/blob/b78a1bbf445743d96c8e4f54e7d2e7cac204342a/packages/%40aws-cdk/aws-lambda/lib/function-base.ts#L81
On the jsii side, it would have to add a check for all overrides to be compatible, i.e. to use the same parameter names.
On the CDK side, we'd have to deprecate all of the incompatible parameter overrides and add properly named ones.
#1919 might be related - using Protocols instead of a Metaclass would ensure that this cannot happen.
Environment
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: