|
1 | | -/* |
2 | | - pybind11/typing.h: Convenience wrapper classes for basic Python types |
3 | | - with more explicit annotations. |
4 | | -
|
5 | | - Copyright (c) 2016 Wenzel Jakob <[email protected]> |
6 | | -
|
7 | | - All rights reserved. Use of this source code is governed by a |
8 | | - BSD-style license that can be found in the LICENSE file. |
9 | | -*/ |
10 | 1 |
|
11 | 2 | #pragma once |
12 | 3 |
|
13 | | -#include <pybind11/pybind11.h> |
14 | | - |
15 | | -PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) |
16 | | - |
17 | | -/* |
18 | | - The following types can be used to direct pybind11-generated docstrings |
19 | | - to have have more explicit types (e.g., `List[str]` instead of `list`). |
20 | | - Just use these in place of existing types. |
21 | | -
|
22 | | - There is no additional enforcement of types at runtime. |
23 | | -*/ |
24 | | - |
25 | | -template <typename... Types> |
26 | | -class Tuple : public tuple { |
27 | | - using tuple::tuple; |
28 | | -}; |
29 | | - |
30 | | -template <typename K, typename V> |
31 | | -class Dict : public dict { |
32 | | - using dict::dict; |
33 | | -}; |
34 | | - |
35 | | -template <typename T> |
36 | | -class List : public list { |
37 | | - using list::list; |
38 | | -}; |
39 | | - |
40 | | -template <typename T> |
41 | | -class Set : public set { |
42 | | - using set::set; |
43 | | -}; |
44 | | - |
45 | | -template <typename Signature> |
46 | | -class Callable; |
47 | | - |
48 | | -template <typename Return, typename... Args> |
49 | | -class Callable<Return(Args...)> : public function { |
50 | | - using function::function; |
51 | | -}; |
52 | | - |
53 | | -PYBIND11_NAMESPACE_BEGIN(detail) |
54 | | - |
55 | | -template <typename... Types> |
56 | | -struct handle_type_name<Tuple<Types...>> { |
57 | | - static constexpr auto name |
58 | | - = const_name("Tuple[") + concat(make_caster<Types>::name...) + const_name("]"); |
59 | | -}; |
60 | | - |
61 | | -template <> |
62 | | -struct handle_type_name<Tuple<>> { |
63 | | - // PEP 484 specifies this syntax for an empty tuple |
64 | | - static constexpr auto name = const_name("Tuple[()]"); |
65 | | -}; |
66 | | - |
67 | | -template <typename K, typename V> |
68 | | -struct handle_type_name<Dict<K, V>> { |
69 | | - static constexpr auto name = const_name("Dict[") + make_caster<K>::name + const_name(", ") |
70 | | - + make_caster<V>::name + const_name("]"); |
71 | | -}; |
72 | | - |
73 | | -template <typename T> |
74 | | -struct handle_type_name<List<T>> { |
75 | | - static constexpr auto name = const_name("List[") + make_caster<T>::name + const_name("]"); |
76 | | -}; |
77 | | - |
78 | | -template <typename T> |
79 | | -struct handle_type_name<Set<T>> { |
80 | | - static constexpr auto name = const_name("Set[") + make_caster<T>::name + const_name("]"); |
81 | | -}; |
82 | | - |
83 | | -template <typename Return, typename... Args> |
84 | | -struct handle_type_name<Callable<Return(Args...)>> { |
85 | | - using retval_type = conditional_t<std::is_same<Return, void>::value, void_type, Return>; |
86 | | - static constexpr auto name = const_name("Callable[[") + concat(make_caster<Args>::name...) |
87 | | - + const_name("], ") + make_caster<retval_type>::name |
88 | | - + const_name("]"); |
89 | | -}; |
90 | | - |
91 | | -PYBIND11_NAMESPACE_END(detail) |
92 | | -PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) |
| 4 | +// our changes were merged to upstream |
| 5 | +#include <pybind11/typing.h> |
0 commit comments