diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 624b8ebac..e41ad2abf 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -740,6 +740,13 @@ class type_caster> : public tuple_caster {} template class type_caster> : public tuple_caster {}; +template <> +class type_caster> : public tuple_caster { +public: + // PEP 484 specifies this syntax for an empty tuple + static constexpr auto name = const_name("tuple[()]"); +}; + /// Helper class which abstracts away certain actions. Users can provide specializations for /// custom holders, but it's only necessary if the type has a non-standard interface. template diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py index 9aa5926e9..b37aacff1 100644 --- a/tests/test_builtin_casters.py +++ b/tests/test_builtin_casters.py @@ -368,6 +368,8 @@ def test_tuple(doc): """ ) + assert doc(m.empty_tuple) == """empty_tuple() -> tuple[()]""" + assert m.rvalue_pair() == ("rvalue", "rvalue") assert m.lvalue_pair() == ("lvalue", "lvalue") assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue")