Skip to content

Type annotations #972

Description

@atugushev

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

  • use pytest-annotate to auto add typings (or something similar)
  • add typings incrementally, one PR per module (e.g., 21b7130) to help reviewers

Alternative Solutions

Wait until we drop Python 2 support and add Python 3 style type annotations.

Additional context

Docs:

Useful tools:

Progress

Maintenanse
Add typings to the following files
Final steps

This list must be done after the above lists.

Activity

  1. changed the title [-]Type annotations?[/-] [+]Type annotations[/+] on Oct 26, 2019
  2. atugushev commented on Oct 26, 2019

    @atugushev
    MemberAuthor

    Hey, @jazzband/pip-tools. Please, join the discussion. Have you any other thoughts or helpful tools we could use to integrate type annotations?

  3. webknjaz commented on Oct 26, 2019

    @webknjaz
    Member

    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.ini rather than flooding setup.cfg with things that aren't related to packaging.

  4. codingjoe commented on Oct 27, 2019

    @codingjoe
    Member

    @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.ini rather than flooding setup.cfg with 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 via setup.py.
    Then again, it does boil down to taste. I'm am just saying there are may flavors ;)

  5. atugushev commented on Oct 27, 2019

    @atugushev
    MemberAuthor

    @webknjaz

    Could probably use https://github.com/Instagram/MonkeyType to collect types from runtime.

    AFAIK, MonkeyType doesn'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?

  6. atugushev commented on Oct 27, 2019

    @atugushev
    MemberAuthor

    @codingjoe

    @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:

    1. it gives more context to the function/method signature and would help contributors to understand the code
    2. mypy is an extra eye on the code quality, it really helps to find bugs sometimes
    3. 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!

  7. aleksihakli commented on Oct 27, 2019

    @aleksihakli
    Member

    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 :)

  8. codingjoe commented on Oct 27, 2019

    @codingjoe
    Member

    OK if it helps people, sure, I'm not against it.

  9. sfdye commented on Mar 21, 2020

    @sfdye
    Member

    Alternative Solutions
    Wait until we drop Python 2 support and add Python 3 style type annotation

    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.

  10. atugushev commented on Mar 21, 2020

    @atugushev
    MemberAuthor

    @sfdye

    So my question is when are we gonna drop Python 2 support?

    As soon as pip does.

  11. codingjoe commented on Mar 25, 2020

    @codingjoe
    Member

    As soon as pip does.

    So never 😉

  12. atugushev commented on Apr 19, 2020

    @atugushev
    MemberAuthor

    @codingjoe

    So never 😉

    BTW, pip==21.0 (Jan 2021) will be the last version with python 2.7 support, see pypa/pip#8087.

  13. 4 remaining items

  14. atugushev commented on May 4, 2020

    @atugushev
    MemberAuthor

    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!

  15. pradyunsg commented on May 14, 2020

    @pradyunsg
    Contributor

    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.

    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.

  16. sfdye commented on May 15, 2020

    @sfdye
    Member

    So that's 2021 at least

  17. jdufresne commented on Dec 16, 2020

    @jdufresne
    Member

    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.

  18. codingjoe commented on Dec 16, 2020

    @codingjoe
    Member

    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.

  19. atugushev commented on Dec 30, 2020

    @atugushev
    MemberAuthor

    I'm going to prepare the 5.5.0 release soon and then we can drop 2.7/3.5 and finally add type hints!

  20. added a commit that references this issue on Jan 2, 2021
  21. atugushev commented on Feb 4, 2021

    @atugushev
    MemberAuthor

    Started to work on type hints #1310. Any help with review or code is appreciated ❤️

  22. linked a pull request that will close this issueAdd type hints for the writer module #1310on Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to functionalityhelp wantedRequest help from the community

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions