-
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
MyPy throwing type errors when it shouldn't #3931
Comments
You are supposed to use this integration class to glue them together: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events-targets.LambdaFunction.html We use this pattern in many places. |
Please re-read the code I posted. I am using the Which appears to be accurate. Looking at this more closely,
|
Heya -- I believe this bug was closed in error; see my post from a few days ago. Can it be re-opened? |
Sorry about that @alexmv ! I just tried with the following code: some_lambda = aws_lambda.Function(
self, "some-handler",
runtime=aws_lambda.Runtime.PYTHON_3_8,
code=aws_lambda.CfnParametersCode(),
handler="some_package.handler",
retry_attempts=0,
)
aws_events.Rule(
self, "some-rule",
schedule=aws_events.Schedule.cron(minute="*/5"),
targets=[aws_events_targets.LambdaFunction(some_lambda)],
) and I got the following template: Resources:
ServiceCatalogPipelinesomehandlerServiceRoleEC8BC838:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Metadata:
aws:cdk:path: hello-cdk-1/ServiceCatalogPipeline/some-handler/ServiceRole/Resource
ServiceCatalogPipelinesomehandler9B981751:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: ServiceCatalogPipelinesomehandlerLambdaSourceBucketNameParameter56C9663D
S3Key:
Ref: ServiceCatalogPipelinesomehandlerLambdaSourceObjectKeyParameter5B5EE148
Handler: some_package.handler
Role:
Fn::GetAtt:
- ServiceCatalogPipelinesomehandlerServiceRoleEC8BC838
- Arn
Runtime: python3.8
DependsOn:
- ServiceCatalogPipelinesomehandlerServiceRoleEC8BC838
Metadata:
aws:cdk:path: hello-cdk-1/ServiceCatalogPipeline/some-handler/Resource
ServiceCatalogPipelinesomehandlerEventInvokeConfig36490DD4:
Type: AWS::Lambda::EventInvokeConfig
Properties:
FunctionName:
Ref: ServiceCatalogPipelinesomehandler9B981751
Qualifier: $LATEST
MaximumRetryAttempts: 0
Metadata:
aws:cdk:path: hello-cdk-1/ServiceCatalogPipeline/some-handler/EventInvokeConfig/Resource
ServiceCatalogPipelinesomehandlerAllowEventRulehellocdk1ServiceCatalogPipelinesomerule0752F509CACFF320:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName:
Fn::GetAtt:
- ServiceCatalogPipelinesomehandler9B981751
- Arn
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- ServiceCatalogPipelinesomeruleE4CCF127
- Arn
Metadata:
aws:cdk:path: hello-cdk-1/ServiceCatalogPipeline/some-handler/AllowEventRulehellocdk1ServiceCatalogPipelinesomerule0752F509
ServiceCatalogPipelinesomeruleE4CCF127:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: cron(*/5 * * * ? *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- ServiceCatalogPipelinesomehandler9B981751
- Arn
Id: Target0
Metadata:
aws:cdk:path: hello-cdk-1/ServiceCatalogPipeline/some-rule/Resource
Parameters:
ServiceCatalogPipelinesomehandlerLambdaSourceBucketNameParameter56C9663D:
Type: String
ServiceCatalogPipelinesomehandlerLambdaSourceObjectKeyParameter5B5EE148:
Type: String So |
Sorry for not making clear that yeah, this is not about the functionality (which works great!), but about the type-correctness of the I've found two other ones: neither |
Sorry about closing your issue before, I must have misread. Yes, this would seem to be an issue in the Python bindings generated by jsii then. But in that case, shouldn't all interfaces have this problem? |
Paging the jsii team :) |
We recently had MyPy start throwing some new type errors that previously it wasn't. Its likely that previously it wasn't catching this missing implementation and this was fixed in a recent release of MyPy. We can investigate this on the JSII side but its likely that the python bindings are missing MyPy annotations in places. We will have to figure out why this isn't caught during build time as well. |
I'm running into the same issue with import aws_cdk.aws_cloudwatch as cloudwatch
import aws_cdk.aws_kinesis as kds
from aws_cdk import core
class MyStack(core.Stack):
def __init__(self, scope: core.Construct, _id: str, **kwargs) -> None:
super().__init__(scope, _id, **kwargs)
self.template_options.description = "Demo"
stream = kds.Stream(self, "InputStream", shard_count=16)
dashboard = cloudwatch.Dashboard(self, "Dashboard", dashboard_name=core.Aws.STACK_NAME)
incoming_records = cloudwatch.Metric(
namespace="AWS/Kinesis",
metric_name="IncomingRecords",
dimensions={"StreamName": stream.stream_name},
period=core.Duration.minutes(1),
statistic="sum",
)
dashboard.add_widgets(
cloudwatch.GraphWidget(
left=[incoming_records], # 'Metric' is missing following 'IMetric' protocol member
width=24,
title="Kinesis data stream (incoming)",
left_y_axis=cloudwatch.YAxisProps(min=0),
right_y_axis=cloudwatch.YAxisProps(min=0),
)
) Checking types with Mypy results in the following error:
|
what is the workaround for this issue ? i suddenly started to get this error in cdk 1.83.0 |
|
my project is too big and its complaining more than 1000 times :( any other alternative than supressing the type checking on the package? |
@MrArnoldPalmer @RomainMuller any updates on this? All interfaces have this error for me. |
@MrArnoldPalmer @RomainMuller Running into this error as well. |
It has been a long while since this issue was last commented on. Both
Closing as I am unable to reproduce this as of now. Please open a new issue with an up do date reproduction if you encounter this issue again. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
In the Python CDK, attempting to pass
aws_events_targets.LambdaFunction
as the target of anevents.Rule
fails to typecheck:It does run perfectly fine, however -- this is purely an error in the typesystem.
Reproduction Steps
pip install mypy && mypy test.py
Error Log
Environment
Other
It is also possible this is a bug in mypy.
Possible duplicate: #1262
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: