(@aws_cdk): Python: incompatible interface implementations due to differing function argument names
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 267
- Avg merge
- 1d 25m
- Merged PRs (30d)
- 14
Description
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`'s `grantInvoke` method uses `grantee` as its parameter name, whereas `IFunction` uses `identity`. 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.
https://github.com/aws/jsii/issues/1919 might be related - using Protocols instead of a Metaclass would ensure that this cannot happen.
### Environment
- **Framework Version: 1.114
- **Language (Version): Python 3
This is :bug: Bug Report
Contributor guide
Research direction
Read the two linked locations in packages/@aws-cdk/aws-lambda/lib/function-base.ts and compare the interface and implementation parameter names. Then inspect jsii issue 1919 and the jsii override-validation area to determine the affected scope. Done means incompatible overrides are identified and the Python interface and implementation signatures remain compatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100