Skip to content
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

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

Open
pavlobielousov opened this issue Jan 16, 2024 · 2 comments
Open

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

pavlobielousov opened this issue Jan 16, 2024 · 2 comments
Labels
🐞 bug Something isn't working 🎉 released Changes were included to the latest release 👋 response needed Awaiting response from a reporter

Comments

@pavlobielousov
Copy link

pavlobielousov commented Jan 16, 2024

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

@pavlobielousov pavlobielousov added the 🐞 bug Something isn't working label Jan 16, 2024
@vemel
Copy link
Collaborator

vemel commented Jan 21, 2024

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

@vemel
Copy link
Collaborator

vemel commented Apr 25, 2024

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.

@vemel vemel added 👋 response needed Awaiting response from a reporter 🎉 released Changes were included to the latest release labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🎉 released Changes were included to the latest release 👋 response needed Awaiting response from a reporter
Projects
None yet
Development

No branches or pull requests

2 participants