pyca / pynacl

Python binding to the Networking and Cryptography (NaCl) library
https://pynacl.readthedocs.io/
Apache License 2.0
1.06k stars 233 forks source link

Type annotations for `nacl.utils` #697

Closed DMRobertson closed 2 years ago

DMRobertson commented 2 years ago

This applies the changes proposed in #692 to nacl.utils on top of the changes in more recent PRs.

I've annotated nacl.bindings.randombytes_buf_deterministic to appease mypy. It's needed because I configured mypy to require that typed code always calls typed functions, in #694.

Per https://github.com/pyca/pynacl/pull/692#discussion_r733872525 and https://stackoverflow.com/a/44644576/5252017 , I've made sure that the _from_parts accepts a generic cls argument and returns an instance of that cls. I don't think we actually intend for people to subclass EncryptedMessage, but maybe they do. Besides, it's nice to have annotations that are as accurate as possible.

DMRobertson commented 2 years ago

black, flake8 with flake8-import-order and mypy are all happy locally, so fingers crossed CI should be okay. :crossed_fingers: