Skip to content

Python: Fix type annotations in KMS client methods #7520

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

essercodes
Copy link

Updated encrypt/decrypt method signatures to properly handle bytes return types from KMS client operations.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

`kms_client.encrypt` returns type `bytes`. Updated method signatures for encrypt and decrypt. The "Plaintext" returned from `kms_client.decrypt` is also `bytes`, but it should be decoded to `str` to match the parameter type of the encrypt method.
@github-actions github-actions bot added the Python This issue relates to the AWS SDK for Python (boto3) label Jul 12, 2025
@brmur brmur requested a review from tejasgn1 July 21, 2025 14:31
@brmur brmur added the Task A general update to the code base for language clarification, missing actions, tests, etc. label Jul 21, 2025
@@ -75,7 +75,7 @@ def decrypt(self, key_id: str, cipher_text: str) -> bytes:
try:
return self.kms_client.decrypt(KeyId=key_id, CiphertextBlob=cipher_text)[
"Plaintext"
]
].decode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, we don't need use the decode() method here as that is being taken care of on line 201. Having the method returns an error. The other changes look good to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the redundant call to decode() on line 201. The call to decode() should be inside the decrypt() function, making its signature the inverse of encrypt(). Since encode() is called from encrypt(), it makes sense that decode() would be called in decrypt().

Copy link
Contributor

@tejasgn1 tejasgn1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, we don't need use the decode() method here as that is being taken care of on line 201. Having the method returns an error. The other changes look good to me.

essercodes and others added 2 commits July 26, 2025 15:26
I removed the redundant call to decode() on line 201. The call to decode() should be inside the decrypt() function, making its signature the inverse of encrypt(). Since encode() is called from encrypt(), it makes sense that decode() would be called in decrypt().
@essercodes essercodes requested a review from tejasgn1 July 26, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python This issue relates to the AWS SDK for Python (boto3) Task A general update to the code base for language clarification, missing actions, tests, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants