-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type annotations for
nacl.bindings.crypto_aead
. (#699)
Mypy config ----------- Due to CFFI there are lots of `Any`s in play here. So first, adjust the mypy config to tolerate `Any`s 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](https://mypy.readthedocs.io/en/stable/config_file.html#config-file-format) 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: - I marked the constants at the top of the module as `int`s. They're `size_t`s in the corresponding C header. I'm not sure this is important (I think they get used with CFFI only?), but it drives down the number of `Any`s. - The code suggested that `aead` was allowed to be an `Optional[bytes]` because we allow it to be `None` everywhere. I've changed the docstring and annotation to reflect this. I, erm, have no idea if passing `None`/`NULL` to the relevant functions is cryptographically meaningful or safe.
- Loading branch information
1 parent
54a5ee2
commit 6bf77d9
Showing
2 changed files
with
61 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters