Repository navigation
Type annotations #972
Description
Activity
- addedmaintenanceRelated to maintenance processesRelated to maintenance processes
on Oct 26, 2019 Hey, @jazzband/pip-tools. Please, join the discussion. Have you any other thoughts or helpful tools we could use to integrate type annotations?
- addedhelp wantedRequest help from the communityRequest help from the community
on Oct 26, 2019 Could probably use https://github.com/Instagram/MonkeyType to collect types from runtime.
P.S. I think, it's better to use a separate
mypy.inirather than floodingsetup.cfgwith things that aren't related to packaging.Reacted by Hasan Ramezani@atugushev I don't want to discourage you, but I believe effort and return might be a bit out of balance. I don't think there are too many people that use the pip-tools Python API. For most people this is a nice CLI tool. The only people who would benefit from type hints however are people who use the Python API are developers of this package. That being said, good IDEs like PyCharm will give you type hints, whether they are explicit added or not. If this is only about you wanting type hints to develop pip-tools and for some reasons don't have a PyCharm license, you can always apply for an open source license ;)
I'm really just dreading the immense workload this will create especially for the poor soul reviewing it :P
P.S. I think, it's better to use a separate
mypy.inirather than floodingsetup.cfgwith things that aren't related to packaging.@webknjaz I think, I actually prefer having everything in the
setup.cfg. For me it makes packaging easier, since I don't have to prune too many files from dists. That being said, there are also a bunch of tools like Sphinx and the PyTest runner that encourage you to use the setup.cfg, since both command are actually run viasetup.py.
Then again, it does boil down to taste. I'm am just saying there are may flavors ;)Could probably use https://github.com/Instagram/MonkeyType to collect types from runtime.
AFAIK,
MonkeyTypedoesn't support py2 typings comments so that we can afford for now py3 typings.P.S. I think, it's better to use a separate mypy.ini rather than flooding setup.cfg with things that aren't related to packaging.
Personally, I'd prefer to have the tools configs in the
setup.cfg, and I'm quite sure we had discussed it earlier with members (can't find references though, probably with @blueyed?) to collect all configurations there. But I understand your intention, and it seems pretty reasonable. Would you like to file a separate issue so we can discuss it?@atugushev I don't want to discourage you, but I believe effort and return might be a bit out of balance. I don't think there are too many people that use the pip-tools Python API. For most people this is a nice CLI tool. The only people who would benefit from type hints however are people who use the Python API are developers of this package. That being said, good IDEs like PyCharm will give you type hints, whether they are explicit added or not. If this is only about you wanting type hints to develop pip-tools and for some reasons don't have a PyCharm license, you can always apply for an open source license ;)
Actually, I do have PyCharm open source license, and I'm happy to have this opportunity!
My thoughts on typings:
- it gives more context to the function/method signature and would help contributors to understand the code
- mypy is an extra eye on the code quality, it really helps to find bugs sometimes
- typings makes the code more strict
IMO it's worth it. The codebase is not so large (comparing to pip), so it's not going to be too hard to adopt typings, thanks to auto type tools!
Just my 2c: adding explicit typing to the codebase is not that big of a job and definitely makes the code more understandable and maintainable :)
Reacted by 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) and Albert TugushevOK if it helps people, sure, I'm not against it.
Alternative Solutions
Wait until we drop Python 2 support and add Python 3 style type annotationTBH I'd prefer this approach
So my question is when are we gonna drop Python 2 support? the discussion on Packaging and Python 2 is so long that I don't have the time to go through them all 😛
But it's March 2020 now, 3 months into 💀 of Python 2.7.
As soon as
pipdoes.So never 😉
Reacted by Liuyang Wan, Albert Tugushev and read with aiSo never 😉
BTW, pip==21.0 (Jan 2021) will be the last version with python 2.7 support, see pypa/pip#8087.
Reacted by Liuyang Wan and Johannes MaronReacted by read with ai4 remaining items
- removedmaintenanceRelated to maintenance processesRelated to maintenance processes
on Apr 21, 2020 I'd prefer to wait with patience until pip drops Python 2.7 support and then we can use type hinting with a full power!
Reacted by Pradyun GedamI guess there are many ways to add type hints via doc strings. Sphinx annotation (including napoleon) have been around for a while and are supported by all good IDEs.
Except, those aren't supported by mypy or pytype; neither are they "blessed" by a PEP describing them. :)
Anyway, @atugushev's approach also works well.
So that's 2021 at least
Reacted by Albert TugushevGiven that we expect pip to drop Python 2 support in the new year, what do you think about cutting one last pip-tools release and then we continue working towards type hinting the code base today? There is already a PR out there to drop Python 2 #1243.
Doing it now would allow people with some extra free time over the holidays to get some of this work done.
WDYT?
My motivation for including type checking is that it helps provide additional confidence that APIs are being used correctly (both internal and external) during large upgrades and refactorings. I'm happy to lend a hand in adding types to the code incrementally.
Reacted by Johannes Maron and 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко)I would also be for one final Python 2 release and then to drop support it like a hot potato.
Gradual changes seem most practical, no one wants to review and release a 10kloc patch.Reacted by Jon Dufresne and 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко)I'm going to prepare the
5.5.0release soon and then we can drop 2.7/3.5 and finally add type hints!Reacted by Jon Dufresne and Hugo van Kemenade- added a commit that references this issue
on Jan 2, 2021 Started to work on type hints #1310. Any help with review or code is appreciated ❤️
- linked a pull request that will close this issueAdd type hints for the writer module #1310
on Feb 5, 2021 - added 2 commits that reference this issue
on Feb 7, 2021
What's the problem this feature will solve?
It would be nice to have type annotations throughout the codebase. This issue is a general tracking issue of how we would use mypy and typings.
Describe the solution you'd like
Alternative Solutions
Wait until we drop Python 2 support and add Python 3 style type annotations.
Additional context
Docs:
Useful tools:
Progress
Maintenanse
[mypy]section to setup.cfg (Use mypy for static type checking #1275)Add typings to the following files
Final steps
This list must be done after the above lists.
disallow_untyped_defs = Trueto setup.cfg (Enable disallow_untyped_defs for mypy #1350)