question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type mismatch warning in Python

See original GitHub issue

The ability to add event sources to a Lambda is a cool feature, but inference of the common interface seems to fail for SQS event sources. The deployment seems to be successful anyway, which makes me believe the warning is incorrect.

The following snippet is a minimum working example:

class DeploymentsStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        lambda = Function(
            self,
            id='id',
            handler='handler',
            runtime=Runtime.GO_1_X,
            code=Code.from_asset('...'),
        )

        queue = Queue(
            self,
            id='id',
            encryption=QueueEncryption.KMS_MANAGED
        )

        sqs_eventsource = SqsEventSource(
            batch_size=1,
            queue=queue
        )

        lambda.add_event_source(sqs_eventsource)

Even though the sqs_eventsource implements aws_cdk.aws_lambda.IEventSource according to the JSII annotation, and the method add_event_source() accepts the exact same interface, a warning is still issued.

image

I’m not sure whether this is a IDE problem (I’m developing with Intellij IDEA), a JSII issue or a CDK issue. My apologies if this is the wrong place for creating this issue.

Environment

  • CDK Version : 1.11.0 (build 4ed4d96)
  • OS : Mac OSX Catalina

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nmussycommented, Oct 18, 2019

Possibly. I’m not that familiar with JSII either.

To rule out any issue with the editor, you could try to invalidate IntelliJ’s cache, or see if another IDE has the same issue? I think Atom has an alright Python support.

0reactions
garnaatcommented, Oct 21, 2019

This seems to be IDE-specific. I created the following sample:

#!/usr/bin/env python3

from aws_cdk import (
    aws_lambda as _lambda,
    aws_lambda_event_sources as events,
    aws_sqs as sqs,
    core,
)


class FooStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        function = _lambda.Function(
            self, "lambda_function",
            handler='lambda_handler.main',
            runtime=_lambda.Runtime.PYTHON_3_7,
            code=_lambda.Code.asset("./lambda"),
        )

        queue = sqs.Queue(
            self, "myqueue",
            encryption=sqs.QueueEncryption.KMS_MANAGED
        )

        sqs_eventsource = events.SqsEventSource(
            batch_size=1,
            queue=queue
        )

        function.add_event_source(sqs_eventsource)


app = core.App()
FooStack(app, "foo")

app.synth()

With a small no-op Lambda function and then tried editing it in VS Code. It doesn’t complain about the event source as shown above and everything synthesizes correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type mismatch when using subclasses - python - Stack Overflow
When we annotate it with type[DataClass1] it says to the typechecker to look for types of DataClass1. As DataClass2 is a subtype of...
Read more >
Built-in Exceptions — Python 3.11.1 documentation
Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about...
Read more >
Type-Mismatch Error - ISACA
In programming, one common error encountered is a type-mismatch error (different compilers may call it different things).
Read more >
Better warning messages for mismatch type with callback ...
Python. PyCharm reports. Expected type 'FunctionTypeInt', got '(var: int) -> None' instead. Kotlin detected. mypy reports.
Read more >
Set severity override of Visual Studio Code Pylance type ...
In this first example, you can see that it flags start_channel with a red squigly when there's a type mismatch: In this second...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found