Skip to content

Commit e96221b

Browse files
rwgkSkylion007
andauthored
Final manual curation in preparation for global clang-formating (#3712)
* Manual line breaks to pre-empt undesired `clang-format`ing. Informed by work under #3683: 60b7eb4 59572e6 * Manual curation of clang-format diffs involving source code comments. Very labor-intensive and dull. * Pulling .clang-format change from @henryiii's 9057962 * Adding commonly used .clang-format `CommentPragmas:` * Ensure short lambdas are allowed Co-authored-by: Aaron Gokaslan <[email protected]>
1 parent d6c66d2 commit e96221b

21 files changed

+167
-94
lines changed

.clang-format

+19
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,36 @@
33
# clang-format --style=llvm --dump-config
44
BasedOnStyle: LLVM
55
AccessModifierOffset: -4
6+
AllowShortLambdasOnASingleLine: true
67
AlwaysBreakTemplateDeclarations: Yes
78
BinPackArguments: false
89
BinPackParameters: false
910
BreakBeforeBinaryOperators: All
1011
BreakConstructorInitializers: BeforeColon
1112
ColumnLimit: 99
13+
CommentPragmas: 'NOLINT:.*|^ IWYU pragma:'
14+
IncludeBlocks: Regroup
1215
IndentCaseLabels: true
1316
IndentPPDirectives: AfterHash
1417
IndentWidth: 4
1518
Language: Cpp
1619
SpaceAfterCStyleCast: true
1720
Standard: Cpp11
21+
StatementMacros: ['PyObject_HEAD']
1822
TabWidth: 4
23+
IncludeCategories:
24+
- Regex: '<pybind11/.*'
25+
Priority: -1
26+
- Regex: 'pybind11.h"$'
27+
Priority: 1
28+
- Regex: '^".*/?detail/'
29+
Priority: 1
30+
SortPriority: 2
31+
- Regex: '^"'
32+
Priority: 1
33+
SortPriority: 3
34+
- Regex: '<[[:alnum:]._]+>'
35+
Priority: 4
36+
- Regex: '.*'
37+
Priority: 5
1938
...

include/pybind11/buffer_info.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ struct buffer_info {
4444
void *ptr = nullptr; // Pointer to the underlying storage
4545
ssize_t itemsize = 0; // Size of individual items in bytes
4646
ssize_t size = 0; // Total number of entries
47-
std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
47+
std::string format; // For homogeneous buffers, this should be set to
48+
// format_descriptor<T>::format()
4849
ssize_t ndim = 0; // Number of dimensions
4950
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
50-
std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension)
51+
std::vector<ssize_t> strides; // Number of bytes between adjacent entries
52+
// (for each per dimension)
5153
bool readonly = false; // flag to indicate if the underlying storage may be written to
5254

5355
buffer_info() = default;

include/pybind11/cast.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
996996
template <typename T, enable_if_t<!is_pyobject<T>::value, int>>
997997
object object_or_cast(T &&o) { return pybind11::cast(std::forward<T>(o)); }
998998

999-
struct override_unused {}; // Placeholder type for the unneeded (and dead code) static variable in the PYBIND11_OVERRIDE_OVERRIDE macro
999+
// Placeholder type for the unneeded (and dead code) static variable in the
1000+
// PYBIND11_OVERRIDE_OVERRIDE macro
1001+
struct override_unused {};
10001002
template <typename ret_type> using override_caster_t = conditional_t<
10011003
cast_is_temporary_value_reference<ret_type>::value, make_caster<ret_type>, override_unused>;
10021004

@@ -1463,7 +1465,8 @@ handle type::handle_of() {
14631465
}}
14641466

14651467
/// Lets you pass a type containing a `,` through a macro parameter without needing a separate
1466-
/// typedef, e.g.: `PYBIND11_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
1468+
/// typedef, e.g.:
1469+
/// `PYBIND11_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
14671470
#define PYBIND11_TYPE(...) __VA_ARGS__
14681471

14691472
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/chrono.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ template <typename type> class duration_caster {
3838
using rep = typename type::rep;
3939
using period = typename type::period;
4040

41-
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>; // signed 25 bits required by the standard.
41+
// signed 25 bits required by the standard.
42+
using days = std::chrono::duration<int_least32_t, std::ratio<86400>>;
4243

4344
bool load(handle src, bool) {
4445
using namespace std::chrono;

include/pybind11/detail/common.h

+15-9
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@
4242
# endif
4343
# endif
4444
#elif defined(_MSC_VER) && __cplusplus == 199711L
45-
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented)
46-
// Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3 or newer
45+
// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully
46+
// implemented). Unless you use the /Zc:__cplusplus flag on Visual Studio 2017 15.7 Preview 3
47+
// or newer.
4748
# if _MSVC_LANG >= 201402L
4849
# define PYBIND11_CPP14
4950
# if _MSVC_LANG > 201402L && _MSC_VER >= 1910
@@ -722,8 +723,8 @@ template <typename T, typename... Ts>
722723
constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
723724
PYBIND11_NAMESPACE_END(constexpr_impl)
724725

725-
/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
726-
/// none match.
726+
/// Return the index of the first type in Ts which satisfies Predicate<T>.
727+
/// Returns sizeof...(Ts) if none match.
727728
template <template<typename> class Predicate, typename... Ts>
728729
constexpr int constexpr_first() { return constexpr_impl::first(0, Predicate<Ts>::value...); }
729730

@@ -842,7 +843,9 @@ PYBIND11_NAMESPACE_END(detail)
842843

843844
#if defined(_MSC_VER)
844845
# pragma warning(push)
845-
# pragma warning(disable: 4275) // warning C4275: An exported class was derived from a class that wasn't exported. Can be ignored when derived from a STL class.
846+
# pragma warning(disable: 4275)
847+
// warning C4275: An exported class was derived from a class that wasn't exported.
848+
// Can be ignored when derived from a STL class.
846849
#endif
847850
/// C++ bindings of builtin Python exceptions
848851
class PYBIND11_EXPORT_EXCEPTION builtin_exception : public std::runtime_error {
@@ -870,7 +873,9 @@ PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
870873
PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
871874
PYBIND11_RUNTIME_EXCEPTION(import_error, PyExc_ImportError)
872875
PYBIND11_RUNTIME_EXCEPTION(attribute_error, PyExc_AttributeError)
873-
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
876+
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or
877+
/// handle::call fail due to a type
878+
/// casting error
874879
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
875880

876881
[[noreturn]] PYBIND11_NOINLINE void pybind11_fail(const char *reason) { throw std::runtime_error(reason); }
@@ -974,13 +979,14 @@ class any_container {
974979
template <typename It, typename = enable_if_t<is_input_iterator<It>::value>>
975980
any_container(It first, It last) : v(first, last) { }
976981

977-
// Implicit conversion constructor from any arbitrary container type with values convertible to T
982+
// Implicit conversion constructor from any arbitrary container type
983+
// with values convertible to T
978984
template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>::value>>
979985
// NOLINTNEXTLINE(google-explicit-constructor)
980986
any_container(const Container &c) : any_container(std::begin(c), std::end(c)) { }
981987

982-
// initializer_list's aren't deducible, so don't get matched by the above template; we need this
983-
// to explicitly allow implicit conversion from one:
988+
// initializer_list's aren't deducible, so don't get matched by the above template;
989+
// we need this to explicitly allow implicit conversion from one:
984990
template <typename TIn, typename = enable_if_t<std::is_convertible<TIn, T>::value>>
985991
any_container(const std::initializer_list<TIn> &c) : any_container(c.begin(), c.end()) { }
986992

include/pybind11/detail/internals.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,22 @@ struct override_hash {
147147
/// Whenever binary incompatible changes are made to this structure,
148148
/// `PYBIND11_INTERNALS_VERSION` must be incremented.
149149
struct internals {
150-
type_map<type_info *> registered_types_cpp; // std::type_index -> pybind11's type information
151-
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py; // PyTypeObject* -> base type_info(s)
150+
// std::type_index -> pybind11's type information
151+
type_map<type_info *> registered_types_cpp;
152+
// PyTypeObject* -> base type_info(s)
153+
std::unordered_map<PyTypeObject *, std::vector<type_info *>> registered_types_py;
152154
std::unordered_multimap<const void *, instance*> registered_instances; // void * -> instance*
153155
std::unordered_set<std::pair<const PyObject *, const char *>, override_hash> inactive_override_cache;
154156
type_map<std::vector<bool (*)(PyObject *, void *&)>> direct_conversions;
155157
std::unordered_map<const PyObject *, std::vector<PyObject *>> patients;
156158
std::forward_list<ExceptionTranslator> registered_exception_translators;
157-
std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across extensions
159+
std::unordered_map<std::string, void *> shared_data; // Custom data to be shared across
160+
// extensions
158161
#if PYBIND11_INTERNALS_VERSION == 4
159162
std::vector<PyObject *> unused_loader_patient_stack_remove_at_v5;
160163
#endif
161-
std::forward_list<std::string> static_strings; // Stores the std::strings backing detail::c_str()
164+
std::forward_list<std::string> static_strings; // Stores the std::strings backing
165+
// detail::c_str()
162166
PyTypeObject *static_property_type;
163167
PyTypeObject *default_metaclass;
164168
PyObject *instance_base;

include/pybind11/detail/type_caster_base.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ PYBIND11_NOINLINE void instance::allocate_layout() {
426426
space += t->holder_size_in_ptrs; // holder instance
427427
}
428428
size_t flags_at = space;
429-
space += size_in_ptrs(n_types); // status bytes (holder_constructed and instance_registered)
429+
space += size_in_ptrs(n_types); // status bytes (holder_constructed and
430+
// instance_registered)
430431

431432
// Allocate space for flags, values, and holders, and initialize it to 0 (flags and values,
432433
// in particular, need to be 0). Use Python's memory allocation functions: in Python 3.6

include/pybind11/iostream.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ PYBIND11_NAMESPACE_END(detail)
164164
.. code-block:: cpp
165165
166166
{
167-
py::scoped_ostream_redirect output{std::cerr, py::module::import("sys").attr("stderr")};
167+
py::scoped_ostream_redirect output{
168+
std::cerr, py::module::import("sys").attr("stderr")};
168169
std::cout << "Hello, World!";
169170
}
170171
\endrst */

include/pybind11/numpy.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ template <typename T, size_t N> struct array_info<T[N]> : array_info<std::array<
325325
template <typename T> using remove_all_extents_t = typename array_info<T>::type;
326326

327327
template <typename T> using is_pod_struct = all_of<
328-
std::is_standard_layout<T>, // since we're accessing directly in memory we need a standard layout type
328+
std::is_standard_layout<T>, // since we're accessing directly in memory
329+
// we need a standard layout type
329330
#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20150422 || __GLIBCXX__ == 20150426 || __GLIBCXX__ == 20150623 || __GLIBCXX__ == 20150626 || __GLIBCXX__ == 20160803)
330331
// libstdc++ < 5 (including versions 4.8.5, 4.9.3 and 4.9.4 which were released after 5)
331332
// don't implement is_trivially_copyable, so approximate it

include/pybind11/options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class options {
5151

5252
struct state {
5353
bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings.
54-
bool show_function_signatures = true; //< Include auto-generated function signatures in docstrings.
54+
bool show_function_signatures = true; //< Include auto-generated function signatures
55+
// in docstrings.
5556
};
5657

5758
static state &global_state() {

0 commit comments

Comments
 (0)