Skip to content

Commit

Permalink
nb::typed<>: support use in return position (#174)
Browse files Browse the repository at this point in the history
The uses are analogous to those in argument position; for example, you might want to return `nb::iterator` but indicate in the signature that it's an iterator over some specific type. It almost worked already, just had a typo in the `type_caster`.
  • Loading branch information
oremanj authored Apr 5, 2023
1 parent c4be1b6 commit d047790
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions docs/api_core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2130,11 +2130,12 @@ Miscellaneous

.. cpp:struct:: template <typename T, typename D> typed

This helper class provides an an API for overriding the type annotation of
a function argument in generated docstrings. It is particularly helpful
when the type signature is not obvious and must be computed at compile time.
Otherwise, the :cpp:class:`raw_doc` attribute provides a simpler
alternative for taking full control of docstrings and type annotations.
This helper class provides an an API for overriding the type
annotation of a function argument or return value in generated
docstrings. It is particularly helpful when the type signature is
not obvious and must be computed at compile time. Otherwise, the
:cpp:class:`raw_doc` attribute provides a simpler alternative for
taking full control of docstrings and type annotations.

Consider the following binding that iterates over a Python list.

Expand Down
2 changes: 1 addition & 1 deletion include/nanobind/nb_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ template <typename T, typename X> struct type_caster<typed<T, X>> {
return true;
}

static handle from_cpp(const T &src, rv_policy policy,
static handle from_cpp(const T2 &src, rv_policy policy,
cleanup_list *cleanup) noexcept {
return Caster::from_cpp(src.value, policy, cleanup);
}
Expand Down

0 comments on commit d047790

Please sign in to comment.