-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
mypy type annotations #530
Comments
Would you be interested in helping to add type annotations? |
Yup, can get you setup with a simple mypy config |
Is there any progress? I can help with it. |
I'm slowly adding some annotations for usage in my own project . Do you want to integrate the annotations in the Sanic code itself or leave it as a .pyi stub file (that defines the types in a separate file) |
Cython now understands PEP484 and PEP526 type annotations. That means you can run the Cython compiler on (pure) Python files and get decent speed improvements. On my machine it takes def f(x):
return x ** 2 - x
def func_a(a, b, N):
s = 0
dx = (b - a) / N
for i in range(N):
s += f(a + i * dx)
return s * dx The same code with some type annotations runs in import cython as c
def fd(x:c.double):
return x ** 2 - x
def func_d(a:c.double, b:c.double, N:c.int):
i:c.int
s = 0
dx = (b - a) / N
for i in range(N):
s += fd(a + i * dx)
return s * dx Maybe this is something sanic could make use of? |
There are two separate things going on here. First, it probably makes sense to create some,stub files to help developers. Second, making use of Cython. We've talked about this before and it may be in the table for some of the features in 2019. But I would suggest moving this conversation to its own thread. And since it is not a specific enhancement, I'd suggest starting a conversation on the community forums. |
Anyone interested to start working in some stub files? @sjsadowski and @yunstanford, 19.03? |
Yeah, I'd like to optimize it with |
Yeah, this might give some performance boost but I think we should be able to have a pure Python implementation as a fallback in case installing binaries is not possible (ex: using pypy (or any other Python implementation that's not CPython); container Linux images without the proper build tools (there's an issue describing this problem here) and perhaps some other scenarios). |
@vltr The compiled version could be uploaded to pypi as |
@feluxe yeah, well, I not much convinced in using the letter |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
See also #1318. We are talking about using cython for some other performance enhancements (specifically in the router). It might be nice to also see if we can use it to clean up some of the performance issues noted here: https://community.sanicframework.org/t/making-sanic-even-faster/298 |
Is anyone still working on this? If possible, I'd like permission to add some auto generated stubs to the official typeshed repo, and then to start working in actual type information gradually over time. |
You definitely do not need permission ... Nonetheless: permission granted |
It's part of the typeshed rules to get explicit permission: :P Thank you though! |
Are we good with moving forwards type hinting on sanic? |
We have started adding it in certain places. Hopefully we will see more of it. |
Awesome, I am willing to assist on this |
@viniciusd hired! 💪 I'd suggest to start a PR and mark it "WIP". Let me know if you have any questions, or need any direction. |
Great! So I am gonna start type hinting sanic. I should take a better look at the source code so I can make that incremental, probably performing the work on a [sub]module basis. Thoughts on taking Sanic up to 3.6 though? PEP-526 improves the type hinting syntax |
Starting with v19.6 we did bump to 3.6 |
What's the status of this? I would love to assist if needed |
It would be great, @LiraNuna! Now I am free enough to contribute. I feel like creating a tracking issue so it is all organized and neat at one place, idk. Anyway, I guess we can start by adding I propose:
I will start by taking a look at how to set-up the dev environment and checking Sanic's travis-ci pipelines. |
Just created a WIP PR at #1682 in order to address (1). However, it should also address (2) in the very near future. Otherwise, its build won't succeed |
Not WIP anymore, #1682 adds a type checking pipeline |
Amazing thanks so much! |
For posterity's sake, #2006 added a lot of type annotations. |
As this is a Python >= 3.5 library, it would be easy for callers of this library to support or ignore type annotations if they were added.
The text was updated successfully, but these errors were encountered: