-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adding type hinting for cryptography #4275
Comments
We talked with someone at PyCon US this year about type stubs and we decided typeshed was a good place for them to live for now. We're happy for someone to do it, but we have no plans to do it ourselves at this time. |
I looked at this a bit over the weekend and progress is effectively blocked on python/mypy#2922. cryptography makes heavy use of ABC registration so not supporting that is a challenge. If we wanted to do this we would need to either switch all abc registration to subclassing or write a protocol (https://www.python.org/dev/peps/pep-0544/) to match every abc interface we've defined and keep them in sync. Neither of these options is very appealing. We could also bypass the problem by just defining these as |
If the plan is to provide type annotations in the form of .pyi files, does it matter if the .pyi files "pretend" that we are using subclassing instead of ABC registration? I have started putting together (partial) stubs to be able to use mypy on one of my projects: https://github.com/aiortc/aioquic/tree/master/stubs/cryptography |
With |
I believe so, yes |
Another way to go about this might be to simply replace the ABCs with Protocols completely. Protocols can be defined as normal, or as
The one problem is that I don't know of any way to give a To maintain compatibility, you could define the classmethod in an |
I don't think we care about 3rd parties registering implementations of our ABCs, so changing how that works seems fine. |
Okay, in that case I guess we're almost to the point where I could try my hand at a PR... |
FYI I have submitted a PR against |
@reaperhulk and @alex the typings I submitted to typeshed are almost complete. Only the x509 module needs a little more love to fully support all extension types. Could you possibly weigh in on whether the PR against typeshed is going the way you want? I will try running type checks against certbot, any other big cryptography users you can think of? |
mypy 0.750 just shipped, and it includes the type stubs I submitted to |
Since these are going into typeshed already I'm going to close this for now. Once we drop 2.7 support we'll be more capable of directly supporting this in a way that isn't insanely frustrating. |
I'm using your library in a code base that uses typechecking and I'd like to be able to perform the type checking on my usage of cryptography.
One way is to add typed stubs of
cryptography
into typeshed.The text was updated successfully, but these errors were encountered: