-
Notifications
You must be signed in to change notification settings - Fork 308
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
PEP 484 type annotations for Twine #231
Comments
@ygingras Where to |
Ian, the stubs can be anywhere and a |
Let's do that then. =) I've been interested in them for a while, and this wouldn't be a bad project to experiment with them. |
Hey @ygingras how has this been going? |
Tim Abbott of Zulip has written up a guide to adding static type annotations to a pre-existing codebase that folks might find helpful if they want to start working on adding these annotations to twine:
|
Hi everyone. It was probably obvious from my radio silence, but I have move on to different projects and I won't be doing this work myself. I still think the annotations would be useful, but since this was mostly an idea to scratch one of my itches, I think we can safely close this issue unless someone else is particularly excited about this work. |
@waseem18 would you be interested in working on this with me? It's a bit of a big project but it takes place in several steps and over several PRs I think we could make progress. |
I would absolutely love to work on this @brainwane |
A handful of us at PyCon are interested in working on this. @sigmavirus24 @waseem18 did you have strong preferences for using stub files instead of python2-compatible annotations in the code itself? Personally I prefer not having to switch between files to get the type information but can go with the stubs. |
Awesome! I see the PR. I'm recovering from PyCon right now and probably won't have time to come back to this till next week sometime. I started annotating utils.py to start getting a feel for mypy. I think that at least to start, we should turn the strictness down from what you have there and ratchet that up once it's starting to come together. So far I have figured out (among other things) that running the |
The existing PR is #344 |
It's worth noting that annotations in stub files are purely for the benefit of external users of twine as a library (are there many of those?), and bring zero type safety benefit to twine itself. If there are stub files, mypy won't even look at any of the actual twine code. If anything, stub files bring some maintenance burden as they can easily get out of date with the code, and need to be kept updated with all API changes in twine. This maintenance burden could be worth it if there are lots of people using twine's API as a library who will benefit, but I thought twine was mostly a CLI tool? Doing annotations in the code itself (as comments, for Py2 support) is really a totally different thing from stub files, as it allows twine's own code to be type checked, and this also prevents the possibility of them getting out of date. |
Thanks for the feedback, @carljm. There's a proposal for a "real Twine API" in #361, which I'm guessing is some of the motivation for stub files, but maybe @sigmavirus24 can elaborate. As a newbie, it does seem easier to start bringing the value of typing to Twine by doing inline annotation. I'm inclined to take #466 in that direction, most likely using the Python 3 syntax since #437 seems likely to be merged. |
If it's something you want to work on, go for it!
…On Sun, Jul 7, 2019 at 3:23 AM Brian Rutledge ***@***.***> wrote:
@theacodes <https://github.com/theacodes> and @jaraco
<https://github.com/jaraco>: Would you like me to keep working on this?
If so, I'd be inclined to continue with #469
<#469> (which depends on the merge of
#437 <#437>). In the case, #466
<#466> and #344
<#344> could be closed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#231?email_source=notifications&email_token=AAB5I44UXU24GROSETBDFM3P6G73LA5CNFSM4C7XRRKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLIV6A#issuecomment-508988152>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAB5I46EAESCD6G3GFSQBA3P6G73LANCNFSM4C7XRRKA>
.
|
With the merge of #469, we have a passing mypy check via I'm ambitiously aiming for a strict check, ala pypa/packaging. |
Are PRs still welcome to add type annotations to different twine modules? I see there are some of them like |
Yes @deveshks |
@deveshks Yes, though if you don't mind waiting a bit, I've got a process that has worked well for me, that I think will save you time and make PR's easier to submit/review. I'll prioritize running through it again, and document it here. |
Sure thing, What I was planning to do is to add type annotations one by one, and run |
Thanks @deveshks. As a preview, my process has been to use MonkeyType to generate the annotations based on the test suite. As mentioned in that #469, this involves some cleanup, but I found it more straightforward and educational than attempting to do it by hand. However, with that in mind, working on #7 to add test coverage would benefit this process. |
Roadmap to completioni.e., when the Twine codebase passes with the TODO (using the recipe below)
Open questions
References
Recipe for adding annotations Run the test suite under MonkeyType tracing:
Apply the inferred annotations to a module, format the changes, and commit:
Add the module to the strict section of
Review the changes and cleanup as necessary. Look out for:
Open a PR. |
I am done with I can perhaps take up annotating |
That's great @deveshks, but let's do one PR at a time (i.e., just |
Hi @bhrutledge Please let me know if I can take up some of the remaining 5 tasks in the list to help out with this effort. |
@deveshks Thanks again for your enthusiasm, but I don't think there's much parallel work to be done at this point. I've got the changes ready to go for the tasks with my name on them. I think the missing imports and coverage reports are related, and I've already put some work into that, and am keen to see it through. |
Just checked off the last item in the roadmap: #231 (comment). So, I think this is done! Any enhancements to or issues with Twine's type checking should be reported as new issues. Thanks to everyone who contributed along the way, and especially to @deveshks who, in addition to adding type coverage, gave me the nudge I needed to finish this. |
Oh, and how could I forget: huge thanks to @brainwane for getting me started on this in the first place, and helping me put together the roadmap to completion. |
Congratulations and thanks! |
Update 4/25/2020: See #231 (comment) below for the current roadmap to completion.
I am considering adding type annotations to Twine to help my team do static analysis of code that depends on it. Would a pull request containing type annotations be merge back?
More info on type annotations:
PEP 484: https://www.python.org/dev/peps/pep-0484/
mypy, the type-checker of choice these days: http://mypy-lang.org/
Given the need to support Python 2.x, the preferred format for annotations would be as Type Comments, but I would be open to do .pyi stubs if that makes it easier for everyone.
Please provide guidance and requirements and I will take it from there.
The text was updated successfully, but these errors were encountered: