-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more stubs for cryptography #3307
Conversation
The x509 stub still needs some love, I haven't had a chance to properly represent the "Name" class. |
@@ -0,0 +1,13 @@ | |||
class CMACBackend: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably these things have some methods? If you don't have time to stub them all out, we should add a def __getattr__(self, name: str) -> Any
to avoid false positives for people using these classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backends themselves are private API.. so it's debatable whether they should be declared at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are documented, though? Also, they should all have a metaclass=ABCMeta
base. Same is true for several of the interfaces in other files.
One thing I noticed is that the signature for load_pem_private_key looks wrong, I believe the password argument is bytes, not str. |
CI seems to be failing because Python 2 lacks It's a bit annoying having to deal with Python 2 less than 3 months before EOL.. Edit: this is no longer an issue, |
I think the EOL of Python 2 in typeshed is probably going to be later than December 31. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for these stubs! I left some remarks below, not a full review yet.
@@ -0,0 +1,13 @@ | |||
class CMACBackend: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are documented, though? Also, they should all have a metaclass=ABCMeta
base. Same is true for several of the interfaces in other files.
third_party/2and3/cryptography/hazmat/primitives/asymmetric/dsa.pyi
Outdated
Show resolved
Hide resolved
6645405
to
dde4a57
Compare
4fe102a
to
353ba30
Compare
@srittau I have added a lot more stubs, feel free to review. I have extensively read the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very helpful, thank you for the stubs! I am sorry for the delay in reviewing, other things came up. For now I just managed to review up to hazmat/primitives/asymmetric, but I hope to review the rest soon.
A few notes below, none of them showstoppers. Most of them are just repeats of the same issue, but I pointed them out in each place to (hopefully) make it easier to fix.
third_party/2and3/cryptography/hazmat/primitives/asymmetric/padding.pyi
Outdated
Show resolved
Hide resolved
third_party/2and3/cryptography/hazmat/primitives/asymmetric/padding.pyi
Outdated
Show resolved
Hide resolved
third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi
Outdated
Show resolved
Hide resolved
third_party/2and3/cryptography/hazmat/primitives/asymmetric/rsa.pyi
Outdated
Show resolved
Hide resolved
third_party/2and3/cryptography/hazmat/primitives/asymmetric/utils.pyi
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very helpful, thank you for the stubs! I am sorry for the delay in reviewing, other things came up. For now I just managed to review up to hazmat/primitives/asymmetric, but I hope to review the rest soon.
A few notes below, none of them showstoppers. Most of them are just repeats of the same issue, but I pointed them out in each place to (hopefully) make it easier to fix.
Thanks so much for taking the time for this first review, I've addressed all the issues you pointed out. The changes related to abstract properties seem to have broken CI though, it looks as though I need to go over all the subclasses to add the corresponding concrete properties. |
) | ||
|
||
class CipherBackend(metaclass=ABCMeta): | ||
@abstractmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not bother including the various backend API methods -- basically no user should ever be invoking them, so it's a lot of code for relatively little benefit (that's my opinion at least, maybe the approach of typeshed is different)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my opinion too, but as @srittau pointed out in #3307 (comment) these methods are part of the cryptography
documentation.. so public API?
Since @alex is weighing in on this PR, it might be a good time to decide whether these type hints should live in I'm happy with both approaches, as long as it lets me typecheck my code :) |
We're unlikely to be convinced to bring these in-tree for cryptography until we're python3 only and can use the native syntax. |
@alex I'd just like to point out that the syntax of stubs is independent of the supported Python version. Even when checking Python 2.7 code, type checkers will support stub files using newer features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished the review now. Just one more note below. Please note that due to the size of the PR, I didn't compare the stubs against implementation or documentation like I usually do, I just looked for obvious issues.
third_party/2and3/cryptography/hazmat/primitives/ciphers/modes.pyi
Outdated
Show resolved
Hide resolved
Yes, I understand the stubs syntax works in both Python2/3. We don't plan to adopt type hints until they can be done directly inline in the source code. |
Seems sensible. We are happy to have them in typeshed as long as required. |
Looks good, I will merge when the build failure is fixed. |
Let's see if CI completes this time. I caught a couple of other places in Going forward, I don't plan to do a "hit and run", please mention me if any issues crop up related to these new stubs. I also plan to expand the |
Thanks for all your guidance @srittau, this is one friendly project! |
No description provided.