youtype / mypy_boto3_builder

Type annotations builder for boto3 compatible with VSCode, PyCharm, Emacs, Sublime Text, pyright and mypy.
https://youtype.github.io/mypy_boto3_builder/
MIT License
544 stars 36 forks source link

Misleading return type definition for table.get_item() #241

Closed pavlobielousov closed 1 month ago

pavlobielousov commented 8 months ago

Describe the bug The current TypedDict definition for the DynamoDB table get_item() method GetItemOutputTableTypeDef contains "Item" as a required key, however, this is not true. According to the AWS documentation:

If there is no matching item, GetItem does not return any data and there will be no Item element in the response.

Currently, mypy reports any branch of code that questions the existence of the "Item" key as an unreachable code.

To Reproduce Steps to reproduce the behavior:

  1. Install boto3-stubs[dynamodb]
  2. Run mypy on the following code sample
import boto3

db = boto3.resource("dynamodb")
table = db.Table("table-name")
response = table.get_item(Key={"foo": "bar"})

if "Item" in response:
    ...
else:
    # unreachable code according to mypy
    ...
...

Actual output

.../main.py:10: error: Statement is unreachable  [unreachable]

Expected output

No mypy reported errors.

Additional context Windows 11, boto3-stubs installatalled via pipenv, boto3 version 1.34.19

vemel commented 8 months ago

Hello! Thank you for the report. I am currently working on optional keys in response StructureShapes. This looks related to #238

vemel commented 5 months ago

The issue has finally been fixed in mypy_boto3_builder 7.24.0 release. I have also released mypy-boto3-dynamodb 1.34.91 with the fix included. Please update and let me know if it works as expected.