mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
feat(types) Adds special Case for empty C++ tuple type annotation (#5214)
* add special case and unit test * add newline
This commit is contained in:
parent
51c2aa16de
commit
d805e9967f
@ -740,6 +740,13 @@ class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {}
|
|||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};
|
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class type_caster<std::tuple<>> : public tuple_caster<std::tuple> {
|
||||||
|
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
|
/// 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.
|
/// custom holders, but it's only necessary if the type has a non-standard interface.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -368,6 +368,8 @@ def test_tuple(doc):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert doc(m.empty_tuple) == """empty_tuple() -> tuple[()]"""
|
||||||
|
|
||||||
assert m.rvalue_pair() == ("rvalue", "rvalue")
|
assert m.rvalue_pair() == ("rvalue", "rvalue")
|
||||||
assert m.lvalue_pair() == ("lvalue", "lvalue")
|
assert m.lvalue_pair() == ("lvalue", "lvalue")
|
||||||
assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue")
|
assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue")
|
||||||
|
Loading…
Reference in New Issue
Block a user