Skip to content

[FEA]: Type stubs / .pyi files for cuda.bindings and cuda.core #1963

Description

@rparolin

Is your feature request related to a problem? Please describe.

The cuda.bindings module is implemented as a C extension, which means type checkers (mypy, pyright) and IDEs (VS Code, PyCharm) cannot introspect the API for autocompletion, inline documentation, or static type checking without explicit type information.

Describe the solution you'd like

Ship PEP 561-compliant type stubs (.pyi files) for cuda.bindings and other public modules. Ideally these would be:

  • Auto-generated alongside the bindings (to stay in sync with the C API)
  • Distributed inline with the package (with a py.typed marker)

Additional context

This has been requested by users in internal Slack channels. Type stubs are on the roadmap for the cuda.bindings track.

Activity

  1. added this to the cuda.bindings next milestone on Apr 22, 2026
  2. added
    cuda.bindingsEverything related to the cuda.bindings module
    and removed
    triageNeeds the team's attention
    on Apr 22, 2026
  3. mdboom commented on Apr 22, 2026

    @mdboom
    Contributor

    The recent work on the generator will make this a whole lot easier. Because cuda-bindings is largely generated, this should be doable.

    It would also be nice to do this for cuda-core, but Cython doesn't make that easy for hand-written code. We would probably need to create some tool to automatically extract this, since keeping .pyx, .pxd and .pyi files all in sync seems hard to manage.

  4. rparolin commented on Apr 22, 2026

    @rparolin
    CollaboratorAuthor

    @mdboom We could convert this issue into an EPIC and have subissues for cuda.core and cuda.bindings so its all tracked together.

  5. leofang commented on Apr 22, 2026

    @leofang
    Member

    Q:

  6. mdboom commented on Apr 23, 2026

    @mdboom
    Contributor

    What is the relation between this issue and #928?

    I take that as a broader level discussion and exploration of options. I take this one to mean -- our best option is to generate .pyi files from our generator. (And we still don't have a good solution for cuda-core).

    Why isn't the current type annotation enough?

    Type annotations in Cython code (or any compiled extension) can not be read by language servers, like pyright, pylance, ty, mypy etc. which are all designed to parse, but not import, code. .pxd files /feel/ like they should work, but they a mix of C and Cython-specific types which are not the same thing as the types that make up the Python-side typing system.

    Which module was being flagged?

    Not sure what you mean. I just fired up VSCode and Emacs when I got here and was disappointed that it didn't work well with cuda_bindings.

    We actually already generated enough type annotations for driver/runtime/nvrtc (via cython-gen).

    Cython generates some signature metadata etc., but this can't be used by a language server and also is wrong in a bunch of ways (see #928).

  7. added
    enhancementAny code-related improvements
    triageNeeds the team's attention
    on May 1, 2026
  8. 1 remaining item

  9. mdboom commented on May 6, 2026

    @mdboom
    Contributor
  10. jon-edward commented on May 7, 2026

    @jon-edward

    Hello! I’m the creator of stubgen-pyx, I'd be happy to help integrate automatic stub generation or answer any questions

  11. mdboom commented on May 7, 2026

    @mdboom
    Contributor

    Thanks, @jon-edward. When we first started exploring this space a few months ago, things looked a lot harder. Thanks for your stubgen-pyx! I'll reach out and maybe flag you for related reviews as this progresses.

  12. mdboom commented on May 7, 2026

    @mdboom
    Contributor

    As I work through this, the coolest thing is that once you have .pyi files, it's very easy to start doing type checking on those files, which catches not only misspelled type annotations, but uses of undefined members and other things. Since we don't have a Cython linter that does this (yet), it's finding real bugs, such as: #2049

    This feels magical. 🤯

  13. self-assigned this
    on May 7, 2026
  14. jon-edward commented on May 7, 2026

    @jon-edward

    Absolutely, unfortunately Cython tooling is kinda lacking in certain areas which was a major motivator for me to make this

  15. mdboom commented on May 11, 2026

    @mdboom
    Contributor

    Absolutely, unfortunately Cython tooling is kinda lacking in certain areas which was a major motivator for me to make this

    100% agree. I'm really excited to see both stubgen-pyx and cython-lint catch up to pure Python tooling.

  16. added
    packagingAnything related to wheels or Conda packages
    and removed
    triageNeeds the team's attention
    on May 21, 2026
  17. mdboom commented on Aug 10, 2026

    @mdboom
    Contributor

    Moving to cuda.bindings.next milestone. This needs to be after the cybind migration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should docuda.bindingsEverything related to the cuda.bindings moduleenhancementAny code-related improvementspackagingAnything related to wheels or Conda packages

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions