Skip to content

Type stubs? #247

Open
Open

Description

@vergenzt

Would you be open to type stubs being merged into this repo?

Activity

  1. vsajip commented on Jan 14, 2025

    @vsajip
    Owner

    I would prefer separate stubs, at least for now, as the package still supports Python 2.x.

  2. vergenzt commented on Jan 15, 2025

    @vergenzt
    Author

    What if it were proposed in a separate .pyi file, leaving the existing Python-2.x-compatible code unannotated?

  3. vsajip commented on Jan 16, 2025

    @vsajip
    Owner

    That seems more reasonable - by all means propose a .pyi file with typing information, and I'll aim to keep that updated with any API changes. I'm not too familiar with Python typing tools - what would be a reasonable test that the typing information is complete for all APIs?

  4. lovetox commented on Jan 28, 2025

    @lovetox
  5. lovetox commented on Jan 28, 2025

    @lovetox

    #248

    I dont think there is a way to test if the API is typed. All typing tools test the whole code of the project for missing types or type errors, to my knowledge there is no way to tell it "test only public API"

  6. vergenzt commented on Jan 28, 2025

    @vergenzt
    Author

    @lovetox yeah pyright doesn't validate that type stubs are consistent with the base untyped Python code.

    There's a mypy tool that targets this use case: Automatic stub testing (stubtest) - mypy 1.14.1 documentation

    And more discussion here: python/mypy#5028

    I've never attempted this though, so am not yet familiar with the rough edges.

  7. vergenzt commented on Jan 28, 2025

    @vergenzt
    Author

    https://github.com/instagram/MonkeyType looks like a tool that might also be useful!

    MonkeyType uses the sys.setprofile hook provided by Python to interpose on function calls, function returns, and generator yields, and record the types of arguments / return values / yield values.

  8. lovetox commented on Feb 5, 2025

    @lovetox

    I contribute the stubs to typeshed, as after discussion the maintainer dont want to ship the stubs.

    See python/typeshed#13465

  9. kism commented on Aug 15, 2025

    @kism

    So right not typeshed can't take the hints since this repo is not in module format? Or because they aren't up to their standard? If so I can try improve them?

    And we don't want to change this repo to a module layout per #248 ?

    I made a personal fork with type hints, in the module layout.

    Added files

    • lovetox's hints gnupg/__init__.pyi
    • py.typed empty file gnupg/py.typed
    • GitHub action for using mypy to check type stubs
      • python3 -m mypy.stubtest gnupg
    • GitHub action to keep up to date from this repo
      • merges any new changes from vsajip/python-gnupg/master
      • moves gnupg.py to gnupg/__init__.py
      • modifies config.cfg so it builds, and with type hints

    Don't actually use/trust my repo, i'm just a guy. Hinting works fine with my mypy/ty/pyright for my project that uses this module.
    https://github.com/kism/python-gnupg

  10. hugovk commented on Nov 10, 2026

    @hugovk
    Contributor

    I've opened another typeshed PR: python/typeshed#16757.

  11. hugovk commented on Nov 15, 2026

    @hugovk
    Contributor

    This is now merged and types-python-gnupg is now available 🚀
    https://pypi.org/project/types-python-gnupg/

    This issue can be closed.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions