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:
I marked the constants at the top of the module as ints. They're
size_ts 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 Anys.
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.
The next module in the
nacl
directory I looked at pulled in fromnacl.bindings
, so I thought that would be the next best place to work on.Mypy config
Due to CFFI there are lots of
Any
s in play here. So first, adjust the mypy config to tolerateAny
s in the bindings module. The way I've done this is a bit awkward. My first attempt includednacl.bindings.crypto_aead
in the existing block of overrides, together with an additional override fornacl.bindings.*
which relaxed theAny
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:Annotations
Largely copied from #692, which itself cribbed types from docstrings. There are two changes on top of that:
int
s. They'resize_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 ofAny
s.aead
was allowed to be anOptional[bytes]
because we allow it to beNone
everywhere. I've changed the docstring and annotation to reflect this. I, erm, have no idea if passingNone
/NULL
to the relevant functions is cryptographically meaningful or safe.