Skip to content

Commit cabb84a

Browse files
committed
Systematically adding // clang-format off, on around all \rst \endrst blocks.
1 parent 9cc0f9c commit cabb84a

File tree

7 files changed

+99
-13
lines changed

7 files changed

+99
-13
lines changed

include/pybind11/attr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct arithmetic { };
7878
/// Mark a function for addition at the beginning of the existing overload chain instead of the end
7979
struct prepend { };
8080

81+
// clang-format off
8182
/** \rst
8283
A call policy which places one or more guard variables (``Ts...``) around the function call.
8384
@@ -95,7 +96,8 @@ struct prepend { };
9596
T scope_guard;
9697
return foo(args...); // forwarded arguments
9798
});
98-
\endrst */
99+
\endrst */
100+
// clang-format on
99101
template <typename... Ts> struct call_guard;
100102

101103
template <> struct call_guard<> { using type = detail::void_type; };

include/pybind11/cast.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,11 @@ arg_v arg::operator=(T &&value) const {
10861086
template <typename /*unused*/> using arg_t = arg_v;
10871087

10881088
inline namespace literals {
1089+
// clang-format off
10891090
/** \rst
10901091
String literal version of `arg`
1091-
\endrst */
1092+
\endrst */
1093+
// clang-format on
10921094
constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
10931095
} // namespace literals
10941096

include/pybind11/detail/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ extern "C" {
281281
return nullptr; \
282282
} \
283283

284+
// clang-format off
284285
/** \rst
285286
***Deprecated in favor of PYBIND11_MODULE***
286287
@@ -296,6 +297,7 @@ extern "C" {
296297
return m.ptr();
297298
}
298299
\endrst */
300+
// clang-format on
299301
#define PYBIND11_PLUGIN(name) \
300302
PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
301303
static PyObject *pybind11_init(); \
@@ -308,6 +310,7 @@ extern "C" {
308310
} \
309311
PyObject *pybind11_init()
310312

313+
// clang-format off
311314
/** \rst
312315
This macro creates the entry point that will be invoked when the Python interpreter
313316
imports an extension module. The module name is given as the fist argument and it
@@ -329,6 +332,7 @@ extern "C" {
329332
});
330333
}
331334
\endrst */
335+
// clang-format on
332336
#define PYBIND11_MODULE(name, variable) \
333337
static ::pybind11::module_::module_def \
334338
PYBIND11_CONCAT(pybind11_module_def_, name) PYBIND11_MAYBE_UNUSED; \

include/pybind11/embed.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
}
3131
#endif
3232

33+
// clang-format off
3334
/** \rst
3435
Add a new module to the table of builtins for the interpreter. Must be
3536
defined in global scope. The first macro parameter is the name of the
@@ -44,7 +45,8 @@
4445
return "Hello, World!";
4546
});
4647
}
47-
\endrst */
48+
\endrst */
49+
// clang-format on
4850
#define PYBIND11_EMBEDDED_MODULE(name, variable) \
4951
static ::pybind11::module_::module_def \
5052
PYBIND11_CONCAT(pybind11_module_def_, name); \
@@ -87,6 +89,7 @@ struct embedded_module {
8789

8890
PYBIND11_NAMESPACE_END(detail)
8991

92+
// clang-format off
9093
/** \rst
9194
Initialize the Python interpreter. No other pybind11 or CPython API functions can be
9295
called before this is done; with the exception of `PYBIND11_EMBEDDED_MODULE`. The
@@ -99,7 +102,8 @@ PYBIND11_NAMESPACE_END(detail)
99102
of throwing exceptions on errors.)
100103
101104
.. _Python documentation: https://docs.python.org/3/c-api/init.html#c.Py_InitializeEx
102-
\endrst */
105+
\endrst */
106+
// clang-format on
103107
inline void initialize_interpreter(bool init_signal_handlers = true) {
104108
if (Py_IsInitialized())
105109
pybind11_fail("The interpreter is already running");
@@ -110,6 +114,7 @@ inline void initialize_interpreter(bool init_signal_handlers = true) {
110114
module_::import("sys").attr("path").cast<list>().append(".");
111115
}
112116

117+
// clang-format off
113118
/** \rst
114119
Shut down the Python interpreter. No pybind11 or CPython API functions can be called
115120
after this. In addition, pybind11 objects must not outlive the interpreter:
@@ -144,7 +149,8 @@ inline void initialize_interpreter(bool init_signal_handlers = true) {
144149
in the CPython documentation. In short, not all interpreter memory may be
145150
freed, either due to reference cycles or user-created global data.
146151
147-
\endrst */
152+
\endrst */
153+
// clang-format on
148154
inline void finalize_interpreter() {
149155
handle builtins(PyEval_GetBuiltins());
150156
const char *id = PYBIND11_INTERNALS_ID;
@@ -165,6 +171,7 @@ inline void finalize_interpreter() {
165171
}
166172
}
167173

174+
// clang-format off
168175
/** \rst
169176
Scope guard version of `initialize_interpreter` and `finalize_interpreter`.
170177
This a move-only guard and only a single instance can exist.
@@ -177,7 +184,8 @@ inline void finalize_interpreter() {
177184
py::scoped_interpreter guard{};
178185
py::print(Hello, World!);
179186
} // <-- interpreter shutdown
180-
\endrst */
187+
\endrst */
188+
// clang-format on
181189
class scoped_interpreter {
182190
public:
183191
scoped_interpreter(bool init_signal_handlers = true) {

include/pybind11/iostream.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class pythonbuf : public std::streambuf {
135135
PYBIND11_NAMESPACE_END(detail)
136136

137137

138+
// clang-format off
138139
/** \rst
139140
This a move-only guard that redirects output.
140141
@@ -158,7 +159,8 @@ PYBIND11_NAMESPACE_END(detail)
158159
py::scoped_ostream_redirect output{std::cerr, py::module::import("sys").attr("stderr")};
159160
std::cout << "Hello, World!";
160161
}
161-
\endrst */
162+
\endrst */
163+
// clang-format on
162164
class scoped_ostream_redirect {
163165
protected:
164166
std::streambuf *old;
@@ -183,6 +185,7 @@ class scoped_ostream_redirect {
183185
};
184186

185187

188+
// clang-format off
186189
/** \rst
187190
Like `scoped_ostream_redirect`, but redirects cerr by default. This class
188191
is provided primary to make ``py::call_guard`` easier to make.
@@ -194,6 +197,7 @@ class scoped_ostream_redirect {
194197
scoped_estream_redirect>());
195198
196199
\endrst */
200+
// clang-format on
197201
class scoped_estream_redirect : public scoped_ostream_redirect {
198202
public:
199203
scoped_estream_redirect(std::ostream &costream = std::cerr,
@@ -230,6 +234,7 @@ class OstreamRedirect {
230234

231235
PYBIND11_NAMESPACE_END(detail)
232236

237+
// clang-format off
233238
/** \rst
234239
This is a helper function to add a C++ redirect context manager to Python
235240
instead of using a C++ guard. To use it, add the following to your binding code:
@@ -256,7 +261,8 @@ PYBIND11_NAMESPACE_END(detail)
256261
with m.ostream_redirect(stdout=true, stderr=true):
257262
m.noisy_function_with_error_printing()
258263
259-
\endrst */
264+
\endrst */
265+
// clang-format on
260266
inline class_<detail::OstreamRedirect>
261267
add_ostream_redirect(module_ m, const std::string &name = "ostream_redirect") {
262268
return class_<detail::OstreamRedirect>(std::move(m), name.c_str(), module_local())

include/pybind11/pybind11.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,13 @@ class module_ : public object {
956956
#endif
957957
}
958958

959+
// clang-format off
959960
/** \rst
960961
Create Python binding for a new function within the module scope. ``Func``
961962
can be a plain C++ function, a function pointer, or a lambda function. For
962963
details on the ``Extra&& ... extra`` argument, see section :ref:`extras`.
963964
\endrst */
965+
// clang-format on
964966
template <typename Func, typename... Extra>
965967
module_ &def(const char *name_, Func &&f, const Extra& ... extra) {
966968
cpp_function func(std::forward<Func>(f), name(name_), scope(*this),
@@ -971,6 +973,7 @@ class module_ : public object {
971973
return *this;
972974
}
973975

976+
// clang-format off
974977
/** \rst
975978
Create and return a new Python submodule with the given name and docstring.
976979
This also works recursively, i.e.
@@ -981,6 +984,7 @@ class module_ : public object {
981984
py::module_ m2 = m.def_submodule("sub", "A submodule of 'example'");
982985
py::module_ m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
983986
\endrst */
987+
// clang-format on
984988
module_ def_submodule(const char *name, const char *doc = nullptr) {
985989
std::string full_name = std::string(PyModule_GetName(m_ptr))
986990
+ std::string(".") + std::string(name);
@@ -1007,13 +1011,15 @@ class module_ : public object {
10071011
*this = reinterpret_steal<module_>(obj);
10081012
}
10091013

1014+
// clang-format off
10101015
/** \rst
10111016
Adds an object to the module using the given name. Throws if an object with the given name
10121017
already exists.
10131018
10141019
``overwrite`` should almost always be false: attempting to overwrite objects that pybind11 has
10151020
established will, in most cases, break things.
10161021
\endrst */
1022+
// clang-format on
10171023
PYBIND11_NOINLINE void add_object(const char *name, handle obj, bool overwrite = false) {
10181024
if (!overwrite && hasattr(*this, name))
10191025
pybind11_fail("Error during initialization: multiple incompatible definitions with name \"" +
@@ -1028,12 +1034,14 @@ class module_ : public object {
10281034
struct module_def {};
10291035
#endif
10301036

1037+
// clang-format off
10311038
/** \rst
10321039
Create a new top-level module that can be used as the main module of a C extension.
10331040
10341041
For Python 3, ``def`` should point to a statically allocated module_def.
10351042
For Python 2, ``def`` can be a nullptr and is completely ignored.
10361043
\endrst */
1044+
// clang-format on
10371045
static module_ create_extension_module(const char *name, const char *doc, module_def *def) {
10381046
#if PY_MAJOR_VERSION >= 3
10391047
// module_def is PyModuleDef
@@ -2173,14 +2181,16 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
21732181
}
21742182
PYBIND11_NAMESPACE_END(detail)
21752183

2184+
// clang-format off
21762185
/** \rst
21772186
Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr.
21782187
21792188
:this_ptr: The pointer to the object the overridden method should be retrieved for. This should be
21802189
the first non-trampoline class encountered in the inheritance chain.
21812190
:name: The name of the overridden Python method to retrieve.
21822191
:return: The Python method by this name from the object or an empty function wrapper.
2183-
\endrst */
2192+
\endrst */
2193+
// clang-format on
21842194
template <class T> function get_override(const T *this_ptr, const char *name) {
21852195
auto tinfo = detail::get_type_info(typeid(T));
21862196
return tinfo ? detail::get_type_override(this_ptr, tinfo, name) : function();
@@ -2200,6 +2210,7 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
22002210
} \
22012211
} while (false)
22022212

2213+
// clang-format off
22032214
/** \rst
22042215
Macro to populate the virtual method in the trampoline class. This macro tries to look up a method named 'fn'
22052216
from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return
@@ -2217,22 +2228,26 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
22172228
);
22182229
}
22192230
\endrst */
2231+
// clang-format on
22202232
#define PYBIND11_OVERRIDE_NAME(ret_type, cname, name, fn, ...) \
22212233
do { \
22222234
PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
22232235
return cname::fn(__VA_ARGS__); \
22242236
} while (false)
22252237

2238+
// clang-format off
22262239
/** \rst
22272240
Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERRIDE_NAME`, except that it
22282241
throws if no override can be found.
22292242
\endrst */
2243+
// clang-format on
22302244
#define PYBIND11_OVERRIDE_PURE_NAME(ret_type, cname, name, fn, ...) \
22312245
do { \
22322246
PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
22332247
pybind11::pybind11_fail("Tried to call pure virtual function \"" PYBIND11_STRINGIFY(cname) "::" name "\""); \
22342248
} while (false)
22352249

2250+
// clang-format off
22362251
/** \rst
22372252
Macro to populate the virtual method in the trampoline class. This macro tries to look up the method
22382253
from the Python side, deals with the :ref:`gil` and necessary argument conversions to call this method and return
@@ -2257,13 +2272,16 @@ template <class T> function get_override(const T *this_ptr, const char *name) {
22572272
}
22582273
};
22592274
\endrst */
2275+
// clang-format on
22602276
#define PYBIND11_OVERRIDE(ret_type, cname, fn, ...) \
22612277
PYBIND11_OVERRIDE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
22622278

2279+
// clang-format off
22632280
/** \rst
22642281
Macro for pure virtual functions, this function is identical to :c:macro:`PYBIND11_OVERRIDE`, except that it throws
22652282
if no override can be found.
22662283
\endrst */
2284+
// clang-format on
22672285
#define PYBIND11_OVERRIDE_PURE(ret_type, cname, fn, ...) \
22682286
PYBIND11_OVERRIDE_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
22692287

0 commit comments

Comments
 (0)