@@ -956,11 +956,13 @@ class module_ : public object {
956
956
#endif
957
957
}
958
958
959
+ // clang-format off
959
960
/* * \rst
960
961
Create Python binding for a new function within the module scope. ``Func``
961
962
can be a plain C++ function, a function pointer, or a lambda function. For
962
963
details on the ``Extra&& ... extra`` argument, see section :ref:`extras`.
963
964
\endrst */
965
+ // clang-format on
964
966
template <typename Func, typename ... Extra>
965
967
module_ &def (const char *name_, Func &&f, const Extra& ... extra) {
966
968
cpp_function func (std::forward<Func>(f), name (name_), scope (*this ),
@@ -971,6 +973,7 @@ class module_ : public object {
971
973
return *this ;
972
974
}
973
975
976
+ // clang-format off
974
977
/* * \rst
975
978
Create and return a new Python submodule with the given name and docstring.
976
979
This also works recursively, i.e.
@@ -981,6 +984,7 @@ class module_ : public object {
981
984
py::module_ m2 = m.def_submodule("sub", "A submodule of 'example'");
982
985
py::module_ m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
983
986
\endrst */
987
+ // clang-format on
984
988
module_ def_submodule (const char *name, const char *doc = nullptr ) {
985
989
std::string full_name = std::string (PyModule_GetName (m_ptr))
986
990
+ std::string (" ." ) + std::string (name);
@@ -1007,13 +1011,15 @@ class module_ : public object {
1007
1011
*this = reinterpret_steal<module_>(obj);
1008
1012
}
1009
1013
1014
+ // clang-format off
1010
1015
/* * \rst
1011
1016
Adds an object to the module using the given name. Throws if an object with the given name
1012
1017
already exists.
1013
1018
1014
1019
``overwrite`` should almost always be false: attempting to overwrite objects that pybind11 has
1015
1020
established will, in most cases, break things.
1016
1021
\endrst */
1022
+ // clang-format on
1017
1023
PYBIND11_NOINLINE void add_object (const char *name, handle obj, bool overwrite = false ) {
1018
1024
if (!overwrite && hasattr (*this , name))
1019
1025
pybind11_fail (" Error during initialization: multiple incompatible definitions with name \" " +
@@ -1028,12 +1034,14 @@ class module_ : public object {
1028
1034
struct module_def {};
1029
1035
#endif
1030
1036
1037
+ // clang-format off
1031
1038
/* * \rst
1032
1039
Create a new top-level module that can be used as the main module of a C extension.
1033
1040
1034
1041
For Python 3, ``def`` should point to a statically allocated module_def.
1035
1042
For Python 2, ``def`` can be a nullptr and is completely ignored.
1036
1043
\endrst */
1044
+ // clang-format on
1037
1045
static module_ create_extension_module (const char *name, const char *doc, module_def *def) {
1038
1046
#if PY_MAJOR_VERSION >= 3
1039
1047
// module_def is PyModuleDef
@@ -2173,6 +2181,7 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
2173
2181
}
2174
2182
PYBIND11_NAMESPACE_END (detail)
2175
2183
2184
+ // clang-format off
2176
2185
/* * \rst
2177
2186
Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr.
2178
2187
@@ -2181,6 +2190,7 @@ PYBIND11_NAMESPACE_END(detail)
2181
2190
:name: The name of the overridden Python method to retrieve.
2182
2191
:return: The Python method by this name from the object or an empty function wrapper.
2183
2192
\endrst */
2193
+ // clang-format on
2184
2194
template <class T > function get_override (const T *this_ptr, const char *name) {
2185
2195
auto tinfo = detail::get_type_info (typeid (T));
2186
2196
return tinfo ? detail::get_type_override (this_ptr, tinfo, name) : function ();
@@ -2201,6 +2211,7 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
2201
2211
} \
2202
2212
} while (false )
2203
2213
2214
+ // clang-format off
2204
2215
/* * \rst
2205
2216
Macro to populate the virtual method in the trampoline class. This macro tries to look up a method named 'fn'
2206
2217
from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return
@@ -2218,22 +2229,26 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
2218
2229
);
2219
2230
}
2220
2231
\endrst */
2232
+ // clang-format on
2221
2233
#define PYBIND11_OVERRIDE_NAME (ret_type, cname, name, fn, ...) \
2222
2234
do { \
2223
2235
PYBIND11_OVERRIDE_IMPL (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__); \
2224
2236
return cname::fn (__VA_ARGS__); \
2225
2237
} while (false )
2226
2238
2239
+ // clang-format off
2227
2240
/* * \rst
2228
2241
Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERRIDE_NAME`, except that it
2229
2242
throws if no override can be found.
2230
2243
\endrst */
2244
+ // clang-format on
2231
2245
#define PYBIND11_OVERRIDE_PURE_NAME (ret_type, cname, name, fn, ...) \
2232
2246
do { \
2233
2247
PYBIND11_OVERRIDE_IMPL (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), name, __VA_ARGS__); \
2234
2248
pybind11::pybind11_fail (" Tried to call pure virtual function \" " PYBIND11_STRINGIFY (cname) " ::" name " \" " ); \
2235
2249
} while (false )
2236
2250
2251
+ // clang-format off
2237
2252
/* * \rst
2238
2253
Macro to populate the virtual method in the trampoline class. This macro tries to look up the method
2239
2254
from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return
@@ -2258,13 +2273,16 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
2258
2273
}
2259
2274
};
2260
2275
\endrst */
2276
+ // clang-format on
2261
2277
#define PYBIND11_OVERRIDE (ret_type, cname, fn, ...) \
2262
2278
PYBIND11_OVERRIDE_NAME (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), #fn, fn, __VA_ARGS__)
2263
2279
2280
+ // clang-format off
2264
2281
/* * \rst
2265
2282
Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERRIDE`, except that it throws
2266
2283
if no override can be found.
2267
2284
\endrst */
2285
+ // clang-format on
2268
2286
#define PYBIND11_OVERRIDE_PURE (ret_type, cname, fn, ...) \
2269
2287
PYBIND11_OVERRIDE_PURE_NAME (PYBIND11_TYPE (ret_type), PYBIND11_TYPE (cname), #fn, fn, __VA_ARGS__)
2270
2288
0 commit comments