Replies: 3 comments
-
Good question. Type annotations are generated based on "ListBucketsOutput":{
"type":"structure",
# no `required` key at all
"members":{
"Buckets":{
"shape":"Buckets",
"documentation":"<p>The list of buckets owned by the requester.</p>"
},
...
},
},
"Buckets":{
"type":"list",
"member":{
"shape":"Bucket",
"locationName":"Bucket"
}
},
"Bucket":{
"type":"structure",
# no `required` key as well
"members":{
"Name":{
"shape":"BucketName",
"documentation":"<p>The name of the bucket.</p>"
},
"CreationDate":{
"shape":"CreationDate",
"documentation":"<p>Date the bucket was created. This date can change when making changes to your bucket, such as editing its bucket policy.</p>"
},
"BucketRegion":{
"shape":"BucketRegion",
"documentation":"<p> <code>BucketRegion</code> indicates the Amazon Web Services region where the bucket is located. If the request contains at least one valid parameter, it is included in the response.</p>"
}
},
"documentation":"<p> In terms of implementation, a Bucket is a resource. </p>"
}, I mark all keys in Even for direct return type annotations not all keys are marked as required. I have a list of keys that are still optional even though they are in return type annotations. An example for So, unless a shape explicitly specifies |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick, thorough response! I'll keep looking at more APIs and see if I can find case(s) where the API docs offer |
Beta Was this translation helpful? Give feedback.
-
Thank you! Also, let me know if you find any keys that can potentially be missing in |
Beta Was this translation helpful? Give feedback.
-
I find that many fields in response TypeDicts are Optional when it seems from the API that they aren't. For example:
I get a type checking error from pyright:
This is due to the definition for
BucketTypeDef
:The
Name
field ofBucketTypeDef
isNotRequired
. Is this really the case that there can be a response tolist_buckets
which returnsListBucketsOutputTypeDef
which has a list ofBuckets
but some of the items in the list don't haveName
?I have been adding a bunch of
assert
s to my code to verify that theseNotRequired
fields exist in order to overcome this typing "error" (assuming that the field exists) but it seems unnecessary.Beta Was this translation helpful? Give feedback.
All reactions