Closed DMRobertson closed 2 years ago
I'm not sure what to make of the codecov failures. It notes that the line I've added isn't run in tests. Maybe replacing ...
with pass
will remedy that?
I'm not sure what to make of the codecov failures. It notes that the line I've added isn't run in tests. Maybe replacing
...
withpass
will remedy that?
Or alternatively I could start annotating the tests so they pull in Encoder
and SupportsBytes
---but not sure that's actually useful.
@Dreamsorcerer you mentioned in #660 that you'd be interested in annotations. Would you be able to have a look over these changes?
Thanks for doing this work! There's a bunch here, but I think to make sure we don't get stalled and get this all reviewed quickly we need to add a mypy job (with whatever set of flags/config we need to have it passing), merge that, then incrementally add chunks of this PR so that it's more easily reviewable.
I'd suggest looking at pyca/cryptography to copy the setup we have there for CI and then set up a decent base config (e.g. https://github.com/pyca/cryptography/blob/main/pyproject.toml#L24, but with the right set of changes to work with minimal/no typing at first).
Looks good overall, just a couple of minor points and the lack of CI.
Thank you both for your feedback.
to make sure we don't get stalled and get this all reviewed quickly we need to add a mypy job (with whatever set of flags/config we need to have it passing), merge that, then incrementally add chunks of this PR so that it's more easily reviewable.
I've attempted this at https://github.com/pyca/pynacl/pull/693. Its CI is sad---but I don't think in a way that I've caused? But let's discuss it there.
Fixes #660.
I went on a bit of an annotating spree and I think I managed to get all of the functions in
nacl
annotated. For the most part it was a case of propagating the existing type hints in the docstrings and reformatting them.It's worth highlighting that I'm not a cryptography expert! All eyes on the changes are appreciated.
Methodology:
nacl._sodium
since that's the C extension(?)mypy --disallow-untyped-defs src/nacl
to spot untyped functionsOne thing I'm not sure about: to annotate the
encoder
arguments I made use of atyping.Protocol
. That was added in Python 3.8; I pulled intyping_extensions
so that it's available in Python 3.6 and 3.7. But having done that, I wasn't sure if adding a dependency was a good idea. Perhaps a try-except along these lines might be better?I also ran
mypy --strict
out of curiosity.ffi.buffer(foo, bar)[:]
. From mypy's perspective these have typeAny
, but I was returning them from functions which had been marked as returningbool
.Box.decode
, but I don't think there was anything obviously wrong there---there's just some trickery in passingNone
toBox.__init__
.SealedBox.decrypt
could haveself._private_key = None
, which would contradict the type ofcrypto_box_seal_open
'ssk
argument. This happens if theSealedBox
is created with aPublicKey
, not aPrivateKey
. That probably makes sense: shouldn't be able to decrypt without aPrivateKey
!