Open guilhem-dvr opened 4 months ago
Unfortunately, right now there is no way to tell if the key in output shape is optional or not. I am still investigating it.
By the way, you are getting key error because method name is incorrect: list_object_versionslist_object_versions
By the way, you are getting key error because method name is incorrect: list_object_versionslist_object_versions
corrected, but this doesn't change my issue: the key is optional from the S3 response but the type checker misses that.
I will try to fix it. If you have time you can also take a look at botocore
shapes and help me figure out how optional/required keys are marked for output shapes.
One solution would be to use the same key totality as for input shapes. But it is also not an ideal solution, because almost all keys are optional in input shapes.
Another solution would be to somehow figure out which keys are required in output shapes, but I still have no idea how to do it.
If I use the same rules as for input shapes, this is what I get :
ListObjectVersionsOutputTypeDef = TypedDict(
"ListObjectVersionsOutputTypeDef",
{
"ResponseMetadata": ResponseMetadataTypeDef,
"IsTruncated": NotRequired[bool],
"KeyMarker": NotRequired[str],
"VersionIdMarker": NotRequired[str],
"NextKeyMarker": NotRequired[str],
"NextVersionIdMarker": NotRequired[str],
"Versions": NotRequired[List[ObjectVersionTypeDef]],
"DeleteMarkers": NotRequired[List[DeleteMarkerEntryTypeDef]],
"Name": NotRequired[str],
"Prefix": NotRequired[str],
"Delimiter": NotRequired[str],
"MaxKeys": NotRequired[int],
"CommonPrefixes": NotRequired[List[CommonPrefixTypeDef]],
"EncodingType": NotRequired[Literal["url"]],
"RequestCharged": NotRequired[Literal["requester"]],
},
)
As you see, all keys are marked as not required. I do not think that this is a proper solution.
The issue has finally been fixed in mypy_boto3_builder 7.24.0
release. I have also released mypy-boto3-s3 1.34.91
with the fix included. Please update and let me know if it works as it should.
Describe the bug
ListObjectVersionsOutputTypeDef
has the keyCommonPrefixes
typed as aList[CommonPrefixTypeDef]
, but the key can be missing in the response tolist_object_versions
.To Reproduce Steps to reproduce the behavior:
boto3-stubs[s3]
mypy
/pyright
on the following code sampleActual output
The
CommonPrefixes
is missing from the response and the snippet fails when running on a real-life example.Expected output
There is no expected output, I would have liked my type checker to warn me about a potentially missing key.
Additional context I'm using macOS 14.2, python 3.9.5, poetry 1.8.1 to manage dependencies, boto3 & boto3-stubs 1.34.31
An example of a response I got from AWS where the key
CommonPrefixes
is missing.