powertools-lambda-python
powertools-lambda-python copied to clipboard
Static typing: overloads for SecretsProvider.get()
Static type checker used
mypy (project's standard)
AWS Lambda function runtime
3.11
Powertools for AWS Lambda (Python) version
latest (2.39.1)
Static type checker info
parameters.get_secret() has overloads to vary its return type based on the transform parameter. Would it be possible for BaseProvider.get() to have the same overloads? For context, I am using SecretsProvider so that I can bring my own boto3 client.
Also, looking at those existing overloads, are the binary and auto cases backwards? It has:
# ...
transform: Literal["binary"],
# ...
) -> Union[str, dict, bytes]: ...
# ...
transform: Literal["auto"],
# ...
) -> bytes: ...
I would have expected binary would return bytes, and auto would return str | dict | bytes?
Thank you for your work on Powertools!
Code snippet
from aws_lambda_powertools.utilities import parameters
import boto3
secret1 = parameters.get_secret('test_secret', transform='json')
reveal_type(secret1) # dict
client = boto3.client('secretsmanager')
provider = parameters.SecretsProvider(boto3_client=client)
secret2 = provider.get('test_secret', transform='json')
reveal_type(secret2) # str | dict | bytes | None; would like dict
reveal_type(parameters.get_secret('test_secret')) # str; OK
reveal_type(parameters.get_secret('test_secret', transform='json')) # dict; OK
reveal_type(parameters.get_secret('test_secret', transform='binary')) # str | dict | bytes; should be bytes?
reveal_type(parameters.get_secret('test_secret', transform='auto')) # bytes; should be str | dict | bytes?
Possible Solution
No response
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
Hello @rtandy! Thanks for opening this issue, although we don't fully support typing checking and some utilities are very hard to resolve without major refactoring, this topic is something we are always looking to improve here at Powertools.
Do you want to work in a PR to fix this? I can help with that if you need any help.
Thanks
Closing this issue as it's been open for a while now, and we didn't have much customer feedback. Please open a new one if it's still an issue.
⚠️COMMENT VISIBILITY WARNING⚠️
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.