-
-
Notifications
You must be signed in to change notification settings - Fork 946
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
feat: add type information - mypy support #1350
Comments
This is an example of a separate stubs package for numpy https://github.com/numpy/numpy-stubs |
I'm still new to using mypy and I realized today we already have typing information for falcon, I just didn't know how to utilize it: def on_post(self, req: falcon.Request, res: falcon.Response): This gives me what I'm looking for. I'm going to leave this open to get clarification on the current state of type information in the repository to see if there is help needed anywhere for it. |
so the current state of falcon types is that they work well for annotations, but not for running mypy. When I run mypy on my project, I get errors like
I think this is because mypy doesn't look directly in site-packages unless it finds PEP 561 implementation or stubs. I've created this falcon-stubs project using stubgen: https://github.com/CoreyCole/falcon-stubs Putting these in my project folder, i.e. |
Are maintainers here ok with me leaving those stubs up and open sourced for others to use/contribute to? |
Would be lovely if falcon supported PEP 561 |
@CoreyCole Falcon is open source software with a permissive license, you are very welcome to do any derivative work 🙂 It may be interesting and useful for users incorporating As for maintaining it officially with Falcon, it is always the question of cost, testing, available bandwidth etc. |
Now that we have dropped support for Python 2.7, let's move forward with adding type hints to Falcon's public interface directly via annotations. |
I could help with that. Do I work against the last tag ( |
Hi @jxub ! You check out directly from master 👍 . |
@vytas7 Perfect, thanks! |
I've created a first PR to review the API class annotations (mostly for myself) at jxub#1. I'm planning of getting rid of these type aliases on top in the api.py file ASAP. However, some types, like the handlers, have pretty complex signatures so I have to rely on the |
Important: it seems that Cython can now pick up and enforce those type annotations. We'll need to tread carefully when it comes to performance-sensitive parts, and we may need to tell Cython not to actually use those annotations in cases where they only lead to slowdowns. |
Here are the relevant bit in the cython docs. Just to specify, I've tried only a very naive test, so I don't think a meaningful conclusion could be drawn from it |
What's the status of this issue? Does anyone have any experience using Falcon with types? For context, I'm investigating replacing bottle in our product with Falcon. This project looks really exciting 💯, but worried about production readiness in the absence of static type checking |
@mcobzarenco My static type checker tells me:
and using So I guess the state is that falcon does not yet support static type checkers like MyPy or PyRight. |
What else is expected of this ticket? Is it a matter of expanding/updating the stubs project? |
Is there any updates on this issue? As far as I can find, currently the only stubs available is the 3 year old ones found in the external repository. Trying to develop with type checking enabled is quite a hassle unfortunately. |
Hi @hojlind ! However, now that the above has been delivered, we're working on merging the PR backlog, and brainstorming features for the 3.x series: #1894. Typing is on our radar, but we haven't decided its priority yet vs other potential improvements. (I've added it to the roadmap issue though.) |
That sounds great! I am rather new to doing larger projects in python, and equally new to how typing works in python, and what the general sentiment about adding types everywhere is. Adding stubs next to the source itself however, as suggested in #1894 sounds like a good idea, as long as the time is there for it of course :) |
As of PEP 561 it is now possible for packages to provide typing information, with different options of how to do so. I'm wondering what would be the preferred course of action to include these.
It seems we could start with partial stubs where we could define things that would be most helpful/commonly used (i.e. request/response)
The text was updated successfully, but these errors were encountered: