Type mismatch warning in Python
See original GitHub issueThe 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.
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:
- Created 4 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
This seems to be IDE-specific. I created the following sample:
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.