Skip to content

feat(types): updated py::capsule type hint to use new types.CapsuleType #5567

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

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

timohl
Copy link
Contributor

@timohl timohl commented Mar 16, 2025

Description

Python 3.13 adds types.CapsuleType.
This PR changes the type hint for py::capsule to the new type.

One open question:
Should I only enable types.CapsuleType for Python Version>=3.13 or for all versions?
Since this only changes type hints/signature it is only in strings and no import is required, so tests still work.
typing.Annotated is already in use without version guard and requires Python Version >= 3.9.
Nanobind falls back to typing_extensions.CapsuleType in previous versions.

Suggested changelog entry:

Updated type hint for ``py::capsule`` to ``type.CapsuleType``

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me: capsule never existed as a type (AFAIK), so this seems strictly better.

Waiting to see if @henryiii wants to chime in.

Copy link
Collaborator

@henryiii henryiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now. If we add the fallback someday we should also add it for typing.Annotated.

@rwgk rwgk merged commit 9f08625 into pybind:master Mar 18, 2025
80 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Mar 18, 2025
@henryiii henryiii changed the title Updated py::capsule type hint to use new types.CapsuleType feat(types): updated py::capsule type hint to use new types.CapsuleType Mar 31, 2025
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants