-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
Type annotations #972
Comments
Hey, @jazzband/pip-tools. Please, join the discussion. Have you any other thoughts or helpful tools we could use to integrate type annotations? |
Could probably use https://github.com/Instagram/MonkeyType to collect types from runtime. P.S. I think, it's better to use a separate |
@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
@webknjaz I think, I actually prefer having everything in the |
AFAIK,
Personally, I'd prefer to have the tools configs in the |
Actually, I do have PyCharm open source license, and I'm happy to have this opportunity! My thoughts on typings:
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 :) |
OK if it helps people, sure, I'm not against it. |
TBH 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 |
So never 😉 |
BTW, pip==21.0 (Jan 2021) will be the last version with python 2.7 support, see pypa/pip#8087. |
Correction: pip 21.0 (Jan 2021) will be the first version to drop support for Python 2.7. pip 20.3 (October 2020) will be the last version to support Python 2.7. |
Yes, finally. I sure you can tell, but boy am I looking forward to Python 2 dying ☠️ |
Why not add |
I 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. I would probably go with Google Style annotations, since they are human and machine-readable. After all, we make documentation for humans not machines. That being said, I don't see a huge advantage of using adding type hints. This isn't a package that a lot of people interact with on a Python API level, but rather via CLI. Therefore, I am only in favor of adding type hints, if they do not slow down regular development or otherwise introduce complexity. |
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! |
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 |
Given 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. |
I would also be for one final Python 2 release and then to drop support it like a hot potato. |
I'm going to prepare the |
Type checking helps give confidence that APIs are being used correctly, especially during large refactoring (e.g. eventually dropping Python 2 support). This initial pass only includes type annotations that were necessary to make mypy pass. Future pull requests will add types for the rest of the project once the workflow is established. pip has started including type annotation in a subset of its code. When major changes to pip are released, the type checking will help identify API mismatches and areas to adjust. mypy is configured to be as strict as possible without introducing errors. The configuration is a subset of the --strict CLI argument. Refs #972
Started to work on type hints #1310. Any help with review or code is appreciated ❤️ |
This option is part of the set of "strict" mypy options, bringing the project closer to full strict checking. https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport > By default, imported values to a module are treated as exported and > mypy allows other modules to import them. This flag changes the > behavior to not re-export unless the item is imported using from-as or > is included in `__all__`. A side benefit of using `__all__` is that it allows removing the flake8 exceptions from the code base. Now `__init__.py` files are checked too. Refs: #972
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 = True
to setup.cfg (Enable disallow_untyped_defs for mypy #1350)The text was updated successfully, but these errors were encountered: