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.bindings.crypto_aead`. #699

Closed DMRobertson closed 2 years ago

DMRobertson commented 2 years ago

The next module in the nacl directory I looked at pulled in from nacl.bindings, so I thought that would be the next best place to work on.

Mypy config

Due to CFFI there are lots of Anys in play here. So first, adjust the mypy config to tolerate Anys in the bindings module. The way I've done this is a bit awkward. My first attempt included nacl.bindings.crypto_aead in the existing block of overrides, together with an additional override for nacl.bindings.* which relaxed the Any checks. This doesn't work, and the mypy docs recognise this as being unfortunate.

I then tried to target the addtional override to just nacl.bindings.crypto_aead, but this failed with:

pyproject.toml: toml config file contains [[tool.mypy.overrides]]
sections with conflicting values. Module 'nacl.bindings.crypto_aead' has
two different values for 'disallow_any_expr'

Annotations

Largely copied from #692, which itself cribbed types from docstrings. There are two changes on top of that:

reaperhulk commented 2 years ago

We can probably do slightly larger PRs if that helps you out a bit. If they're < 400 lines of diff they're still reviewable 😄