Closed perlow closed 1 year ago
Hello!
Thanks for the feature request. Yes, I was thinking about it. As you see, for now, I only have Literals and TypedDicts. It is a good idea to also have named type annotations for large types.
There are several issues with this approach:
Shape
, so it has to reuse the parent name, e.g. ScanOutputTableLastEvaluatedKeyValueType
extras
and store types theredynamodb
this is relatively easy to do because this particular type is created by me. Should we also name large Unions
extracted from botocore. Shape
I will think about it. Also, feel free to share your ideas.
Four months passed, and now we have named unions in boto3-stubs>=1.28.16.post1
. You can find them in type_defs.py
files. In your case, you can use:
import boto3
from mypy_boto3_dynamodb.type_defs import TableAttributeValueTypeDef
def scan() -> list[dict[str, TableAttributeValueTypeDef]]:
table = boto3.resource("mypy_boto3_dynamodb").Table("my_table")
result = table.scan()
return result["Items"]
Please let me know if you have any ideas about the implementation, or if you face any issues. Thank you for the feature request again!
An example of this is
LastEvaluatedKey
ofScanOutputTableTypeDef
. It has the inline-typeThis means that if code calling
table.scan
needs to return this to its caller, it needs to replicate that very large type definition. Ideally, this would be a named type like LastEvaluatedKeyTypeDef which could then be referenced in application code.