-
Notifications
You must be signed in to change notification settings - Fork 3k
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 mypy annotations throughout the codebase #4748
Comments
Is this really worth the effort, considering pip has no public API and the fact that it increases the maintenance load? |
If the annotations could be added directly to the code, that wouldn't be a problem, but as long as .pyi files must be used... |
Yes. It's a way to catch bugs and serves as useful insight into what a function expects; which helps with the what-is-going-where problem in the codebase.
From what I gather, |
Alright, that would work then I guess. |
As an aside, @agronholm you might want to take a look at how the configuration module is annotated. :) |
I've gone ahead and generated stubs for pip via MonkeyType and put them at https://github.com/pradyunsg/pip/tree/experiment/monkeytype-annotations/stubs/pip for now. I believe they won't be completely correct since they were generated automatically and only using on the code paths covered by the tests. They should, however, serve as a good reference for someone working to add |
This issue is a good starting point for anyone who wants to help out with pip's development -- it's simple and the process of fixing this should be a good introduction to pip's development workflow. See the discussion above to understand what the desired fix is. |
Dropping a reminder comment that someone needs to update OP based on the merged PRs from the Bloomberg sprint. I'll try to come around to it sooner than later. |
@chrahunt ^ :) |
@pradyunsg I'll help with |
There are still some 300+ functions missing annotations that I saw setting @pradyunsg, I saw that, the feature of pyannotate I thought may be useful is its ability to merge the output from a test run with the code itself as type annotation comments. Locally I have been able to generate the output JSON files for test runs based on the main pytest process and subprocess executions. We'll see if the output can be merged easily or if it would be as much work as hand-merging from separate annotation files. |
Yep yep. I've become familiar with both these tools to an unreasonable extent over the past few weeks. 🌈 My take that no one asked for: It's definitely worth exploring automation here, though since this is a one-off thing (it's not like we're going to add annotations post-facto again), I'm not sure where the cut off lies to just doing them manually vs using automation so I'll defer to whoever is doing the work to choose. 🙃 |
I just merged PR #6704 FYI (progress on Also, to help with the strict optional stuff, I think it would be helpful to add to I also think it would be good to put a typed version of |
@cjerdonek Turns out mypy supports inline configuration on a per-file basis and we should probably adopt that. |
File that fail with disallow_untyped_defs = False:
Files that fail with strict_optional = True:
|
#6750 does this now. :) |
Right now, what we'd want to tackle is the removal of
Ideally, we'd do one-file-per-PR for this, since that's much easier to review that big PRs. |
Annd, this is done now. Thanks everyone who has helped drive this to completion! ^>^ |
We adopted the use of mypy in #4545. This issue is for discussing and tracking how we actually want to utilize mypy in pip's codebase.
The text was updated successfully, but these errors were encountered: