aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.68k stars 3.93k forks source link

IAM: Python type IPrincipal is incompatible with ServicePrincipal #31454

Open fraghag opened 2 months ago

fraghag commented 2 months ago

Describe the bug

This bug was already reported previously #30431.

Not sure why it was not addressed and the issue closed, so opening a new one. The AWS plugin in VSCode is quite extensive so it seems to be a very encouraged tool to use for AWS development, but this bug makes the coding experience very poor.

Also the _statement parameter looks very weird

principal = iam.AccountPrincipal("123456789012")
principal.add_to_principal_policy(_statement=iam.PolicyStatement())

and if it's called like that instead of statement like it is in IPrincipal for a reason it's seems like an ugly hack.

If you think that you are doing the correct thing with regards to python typing then we should start a discussion about it with pyright developers.

Regression Issue

Last Known Working CDK Version

No response

Expected Behavior

I'm expecting to not get typing errors when writing the code as it is intended.

Current Behavior

Raises typing error.

Reproduction Steps

See #30431

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.154.1 (build febce9d)

Framework Version

No response

Node.js Version

v20.12.2

OS

Ubuntu 22.04.4 LTS

Language

Python

Language Version

Python 3.12

Other information

No response

pahud commented 2 months ago

Yes i can produce this error when I install pyright VSCode extension

image

But I won't have that if I install Pylance.

I guess this might be a Pyright bug?

fraghag commented 2 months ago

Pylance uses pyright under the hood. But pylance does not highlight typing errors by default, you have to explicitly tell it to in the settings with:

    "python.analysis.typeCheckingMode": "standard",

And also I first checked this with pyright and the guy there says that pyright is doing the right thing and his argument makes sense to me. https://github.com/microsoft/pyright/issues/8984

gshpychka commented 1 month ago

This is not a Pyright bug - in Python, argument names have to match.

This is a limitation of JSII - tracked here: https://github.com/aws/jsii/issues/4541