Skip to content

Stubs for boto.kms #1081

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

Merged
merged 6 commits into from
Apr 4, 2017
Merged

Stubs for boto.kms #1081

merged 6 commits into from
Apr 4, 2017

Conversation

ashwch
Copy link
Contributor

@ashwch ashwch commented Mar 23, 2017

@JelleZijlstra
Copy link
Member

Thanks for your contribution! I'd prefer to have types for every parameter in new stubs, but if that's too much work in this case I'll merge this PR as is.

@ashwch
Copy link
Contributor Author

ashwch commented Mar 24, 2017

@JelleZijlstra Let me have a look, don't merge it for now.

@ashwch
Copy link
Contributor Author

ashwch commented Mar 24, 2017

@JelleZijlstra Updated. Please check.

@JelleZijlstra
Copy link
Member

Thanks! Would you mind adding some return types too? (Should have mentioned that in my first message.) Declaring the return types is helpful in having mypy typecheck your code, because otherwise any value you get back from a function in this module will just be typed as Any.

#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

def regions(): ...
Copy link
Member

Choose a reason for hiding this comment

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

Returns a List[boto.regioninfo.RegionInfo] according to the docs.

def enable_key(self, key_id: str): ...
def enable_key_rotation(self, key_id: str): ...
def encrypt(self, key_id: str, plaintext: bytes, encryption_context: Optional[Dict] = ..., grant_tokens: Optional[List] = ...): ...
def generate_data_key(self, key_id: str, encryption_context: Optional[Dict] = ..., number_of_bytes: Optional[int] = ..., key_spec: Optional[str] = ..., grant_tokens: Optional[List] = ...): ...
Copy link
Member

Choose a reason for hiding this comment

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

The documentation says "map" as the type of the encryption_context argument, which I assume means it accepts any mapping. Maybe we should type it as Mapping[str, Any]? (Not sure what exactly the values are supposed to be.) In general it's also good to add type arguments for precision instead of just "Dict" or "List".

def retire_grant(self, grant_token: str): ...
def revoke_grant(self, key_id: str, grant_id: str): ...
def update_key_description(self, key_id: str, description: str): ...
def make_request(self, key_id, description): ...
Copy link
Member

Choose a reason for hiding this comment

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

The arguments to this function are actually called "action" and "body", and if I'm reading the source correctly the types are str and bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad here.

@ashwch
Copy link
Contributor Author

ashwch commented Apr 2, 2017

@JelleZijlstra Made the changes, please check.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Just one more comment (although it applies to most return types in this file).

ResponseError = ... # type: Type[Exception]
region = ... # type: Any
def __init__(self, **kwargs) -> None: ...
def create_alias(self, alias_name: str, target_key_id: str) -> Optional[Mapping[str, Any]]: ...
Copy link
Member

Choose a reason for hiding this comment

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

For return types, it's actually better to be precise and write Dict if that's what it returns. As a general rule, we should be permissive in argument types and precise in return types. The first part is so that a type checker will allow people to pass in a custom dictionary-like type if they want to, and the second part is so that people who write code that mutates the dictionary returned from create_alias don't get type errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Will keep this in mind going forward. Updated.

@JelleZijlstra JelleZijlstra self-assigned this Apr 2, 2017
@JelleZijlstra JelleZijlstra merged commit 35b6795 into python:master Apr 4, 2017
@JelleZijlstra
Copy link
Member

Thanks!

@ashwch ashwch deleted the boto-kms branch July 2, 2017 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants