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

Static typing: overloads for SecretsProvider.get() #4622

Open
rtandy opened this issue Jun 25, 2024 · 2 comments
Open

Static typing: overloads for SecretsProvider.get() #4622

rtandy opened this issue Jun 25, 2024 · 2 comments
Assignees
Labels
help wanted Could use a second pair of eyes/hands typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@rtandy
Copy link

rtandy commented Jun 25, 2024

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

@rtandy rtandy added triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.) labels Jun 25, 2024
Copy link

boring-cyborg bot commented Jun 25, 2024

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

@leandrodamascena
Copy link
Contributor

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

@leandrodamascena leandrodamascena self-assigned this Jun 27, 2024
@leandrodamascena leandrodamascena removed the triage Pending triage from maintainers label Jun 27, 2024
@heitorlessa heitorlessa added the help wanted Could use a second pair of eyes/hands label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Could use a second pair of eyes/hands typing Static typing definition related issues (mypy, pyright, etc.)
Projects
Status: Pending customer
Development

No branches or pull requests

3 participants