Skip to content

Commit 4bbac27

Browse files
laramielcopybara-github
authored andcommitted
Minor formatting/include cleanups.
PiperOrigin-RevId: 678453559
1 parent 55916e1 commit 4bbac27

20 files changed

+93
-101
lines changed

pybind11_protobuf/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ cc_library(
7171
deps = [
7272
"@com_google_absl//absl/container:flat_hash_map",
7373
"@com_google_absl//absl/container:flat_hash_set",
74-
"@com_google_absl//absl/meta:type_traits",
7574
"@com_google_absl//absl/strings",
7675
"@com_google_absl//absl/synchronization",
7776
"@com_google_protobuf//:protobuf",

pybind11_protobuf/check_unknown_fields.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
#include <string>
77
#include <vector>
88

9-
#include "google/protobuf/descriptor.h"
10-
#include "google/protobuf/message.h"
11-
#include "google/protobuf/unknown_field_set.h"
129
#include "absl/container/flat_hash_map.h"
1310
#include "absl/container/flat_hash_set.h"
1411
#include "absl/strings/str_cat.h"
1512
#include "absl/strings/str_join.h"
1613
#include "absl/strings/string_view.h"
1714
#include "absl/synchronization/mutex.h"
15+
#include "google/protobuf/descriptor.h"
16+
#include "google/protobuf/message.h"
17+
#include "google/protobuf/unknown_field_set.h"
18+
#include "python/google/protobuf/proto_api.h"
1819

1920
namespace pybind11_protobuf::check_unknown_fields {
2021
namespace {
@@ -103,8 +104,7 @@ bool HasUnknownFields::FindUnknownFieldsRecursive(
103104

104105
// Stop only if the extension is known by Python.
105106
if (py_proto_api->GetDefaultDescriptorPool()->FindExtensionByNumber(
106-
unknown_field_parent_descriptor,
107-
unknown_field_number)) {
107+
unknown_field_parent_descriptor, unknown_field_number)) {
108108
field_fqn_parts.resize(depth);
109109
return true;
110110
}

pybind11_protobuf/check_unknown_fields.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define PYBIND11_PROTOBUF_CHECK_UNKNOWN_FIELDS_H_
33

44
#include <optional>
5+
#include <string>
56

7+
#include "absl/strings/string_view.h"
68
#include "google/protobuf/message.h"
79
#include "python/google/protobuf/proto_api.h"
8-
#include "absl/strings/string_view.h"
910

1011
namespace pybind11_protobuf::check_unknown_fields {
1112

pybind11_protobuf/enum_type_caster.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
#include <pybind11/pybind11.h>
1212
#include <pybind11/pytypes.h>
1313

14-
#include <string>
1514
#include <type_traits>
1615

17-
#include "google/protobuf/descriptor.h"
18-
#include "google/protobuf/generated_enum_reflection.h"
1916
#include "google/protobuf/generated_enum_util.h"
2017

2118
// pybind11 type_caster specialization which translates Proto::Enum types
2219
// to/from ints. This will have ODR conflicts when users specify wrappers for
2320
// enums using py::enum_<T>.
2421
//
25-
// ::google::protobuf::is_proto_enum and ::google::protobuf::GetEnumDescriptor are require
22+
// ::google::protobuf::is_proto_enum and ::google::protobuf::GetEnumDescriptor
23+
// are require
2624
//
27-
// NOTE: The protobuf compiler does not generate ::google::protobuf::is_proto_enum traits
28-
// for enumerations of oneof fields.
25+
// NOTE: The protobuf compiler does not generate
26+
// ::google::protobuf::is_proto_enum traits for enumerations of oneof fields.
2927
//
3028
// Example:
3129
// #include <pybind11/pybind11.h>

pybind11_protobuf/native_proto_caster.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@
1111
// IWYU
1212
#include <Python.h>
1313

14-
#include <functional>
15-
#include <memory>
16-
#include <optional>
17-
#include <string>
1814
#include <type_traits>
19-
#include <utility>
2015

21-
#include "google/protobuf/message.h"
2216
#include "absl/strings/string_view.h"
17+
#include "google/protobuf/message.h"
2318
#include "pybind11_protobuf/enum_type_caster.h"
2419
#include "pybind11_protobuf/proto_caster_impl.h"
2520

26-
// pybind11::type_caster<> specialization for ::google::protobuf::Message types that
27-
// that converts protocol buffer objects between C++ and python representations.
28-
// This binder supports binaries linked with both native python protos
29-
// and fast cpp python protos.
21+
// pybind11::type_caster<> specialization for ::google::protobuf::Message types
22+
// that that converts protocol buffer objects between C++ and python
23+
// representations. This binder supports binaries linked with both native python
24+
// protos and fast cpp python protos.
3025
//
3126
// When passing protos between python and C++, if possible, an underlying C++
3227
// object may have ownership transferred, or may be copied if both instances

pybind11_protobuf/proto_cast_util.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include <string>
1212
#include <unordered_set>
1313
#include <utility>
14-
#include <vector>
1514

16-
#include "google/protobuf/descriptor.pb.h"
1715
#include "absl/container/flat_hash_map.h"
1816
#include "absl/log/check.h"
1917
#include "absl/log/log.h"
@@ -25,6 +23,7 @@
2523
#include "absl/strings/strip.h"
2624
#include "absl/types/optional.h"
2725
#include "google/protobuf/descriptor.h"
26+
#include "google/protobuf/descriptor.pb.h"
2827
#include "google/protobuf/descriptor_database.h"
2928
#include "google/protobuf/dynamic_message.h"
3029

@@ -34,7 +33,6 @@ using ::google::protobuf::Descriptor;
3433
using ::google::protobuf::DescriptorDatabase;
3534
using ::google::protobuf::DescriptorPool;
3635
using ::google::protobuf::DynamicMessageFactory;
37-
using ::google::protobuf::FileDescriptor;
3836
using ::google::protobuf::FileDescriptorProto;
3937
using ::google::protobuf::Message;
4038
using ::google::protobuf::MessageFactory;
@@ -184,10 +182,8 @@ GlobalState::GlobalState() {
184182
// pybind11_protobuf casting needs a dependency on proto internals to work.
185183
try {
186184
ImportCached("google.protobuf.descriptor");
187-
auto descriptor_pool =
188-
ImportCached("google.protobuf.descriptor_pool");
189-
auto message_factory =
190-
ImportCached("google.protobuf.message_factory");
185+
auto descriptor_pool = ImportCached("google.protobuf.descriptor_pool");
186+
auto message_factory = ImportCached("google.protobuf.message_factory");
191187
global_pool_ = descriptor_pool.attr("Default")();
192188
find_message_type_by_name_ = global_pool_.attr("FindMessageTypeByName");
193189
if (hasattr(message_factory, "GetMessageClass")) {
@@ -221,6 +217,7 @@ py::module_ GlobalState::ImportCached(const std::string& module_name) {
221217
if (cached != import_cache_.end()) {
222218
return cached->second;
223219
}
220+
LOG(INFO) << "ImportCached " << module_name;
224221
auto module = py::module_::import(module_name.c_str());
225222
import_cache_[module_name] = module;
226223
return module;

pybind11_protobuf/proto_cast_util.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
#include <pybind11/pybind11.h>
77
#include <pybind11/pytypes.h>
88

9-
#include <functional>
109
#include <memory>
1110
#include <string>
12-
#include <type_traits>
13-
#include <utility>
1411

15-
#include "google/protobuf/descriptor.h"
16-
#include "google/protobuf/message.h"
1712
#include "absl/strings/string_view.h"
1813
#include "absl/types/optional.h"
14+
#include "google/protobuf/descriptor.h"
15+
#include "google/protobuf/message.h"
1916

2017
// PYBIND11_PROTOBUF_ASSUME_FULL_ABI_COMPATIBILITY can be defined by users
2118
// certain about ABI compatibility between all Python extensions in their
@@ -52,10 +49,12 @@ absl::string_view PyBytesAsStringView(pybind11::bytes py_bytes);
5249
// various protobuf-related modules.
5350
void InitializePybindProtoCastUtil();
5451

55-
// Imports a module pertaining to a given ::google::protobuf::Descriptor, if possible.
52+
// Imports a module pertaining to a given ::google::protobuf::Descriptor, if
53+
// possible.
5654
void ImportProtoDescriptorModule(const ::google::protobuf::Descriptor *);
5755

58-
// Returns a ::google::protobuf::Message* from a cpp_fast_proto, if backed by C++.
56+
// Returns a ::google::protobuf::Message* from a cpp_fast_proto, if backed by
57+
// C++.
5958
const ::google::protobuf::Message *PyProtoGetCppMessagePointer(pybind11::handle src);
6059

6160
// Returns the protocol buffer's py_proto.DESCRIPTOR.full_name attribute.

pybind11_protobuf/proto_caster_impl.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
#include <pybind11/pybind11.h>
99
#include <pybind11/pytypes.h>
1010

11-
#include <functional>
1211
#include <memory>
1312
#include <optional>
14-
#include <string>
1513
#include <type_traits>
1614
#include <utility>
1715

18-
#include "google/protobuf/descriptor.pb.h"
1916
#include "google/protobuf/descriptor.h"
17+
#include "google/protobuf/descriptor.pb.h"
2018
#include "google/protobuf/message.h"
2119
#include "pybind11_protobuf/proto_cast_util.h"
2220

@@ -74,8 +72,7 @@ struct proto_caster_load_impl {
7472

7573
owned = std::unique_ptr<ProtoType>(new ProtoType());
7674
value = owned.get();
77-
return owned.get()->ParsePartialFromString(
78-
PyBytesAsStringView(serialized_bytes));
75+
return owned->ParsePartialFromString(PyBytesAsStringView(serialized_bytes));
7976
}
8077

8178
// ensure_owned ensures that the owned member contains a copy of the
@@ -126,8 +123,7 @@ struct proto_caster_load_impl<::google::protobuf::Message> {
126123
src, *descriptor_name)
127124
.release()));
128125
value = owned.get();
129-
return owned.get()->ParsePartialFromString(
130-
PyBytesAsStringView(serialized_bytes));
126+
return owned->ParsePartialFromString(PyBytesAsStringView(serialized_bytes));
131127
}
132128

133129
// ensure_owned ensures that the owned member contains a copy of the
@@ -156,7 +152,8 @@ struct fast_cpp_cast_impl {
156152
(policy == pybind11::return_value_policy::reference ||
157153
policy == pybind11::return_value_policy::reference_internal)) {
158154
throw pybind11::type_error(
159-
"Cannot return a const reference to a ::google::protobuf::Message derived "
155+
"Cannot return a const reference to a ::google::protobuf::Message "
156+
"derived "
160157
"type. Consider setting return_value_policy::copy in the "
161158
"pybind11 def().");
162159
}

pybind11_protobuf/proto_utils.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77

88
#include <pybind11/functional.h>
99

10-
#include <cstddef>
10+
#include <cstdint>
11+
#include <cstdlib>
12+
#include <functional>
1113
#include <memory>
1214
#include <stdexcept>
1315
#include <string>
16+
#include <utility>
1417

15-
#include "google/protobuf/descriptor.pb.h"
18+
#include "absl/strings/str_cat.h"
19+
#include "absl/strings/string_view.h"
1620
#include "google/protobuf/descriptor.h"
21+
#include "google/protobuf/descriptor.pb.h"
1722
#include "google/protobuf/message.h"
1823
#include "google/protobuf/reflection.h"
19-
#include "absl/strings/str_cat.h"
20-
#include "absl/strings/string_view.h"
2124

2225
namespace pybind11 {
2326
namespace google {
@@ -516,7 +519,7 @@ struct FindMapPair {
516519
handle key, bool add_key = true) {
517520
// When using the proto reflection API, maps are represented as repeated
518521
// message fields (messages with 2 elements: 'key' and 'value'). If protocol
519-
// buffers guarrantee a consistent (and useful) ordering of elements,
522+
// buffers guarantee a consistent (and useful) ordering of elements,
520523
// it should be possible to do this search in O(log(n)) time. However, that
521524
// requires more knowledge of protobuf internals than I have, so for now
522525
// assume a random ordering of elements, in which case a O(n) search is

pybind11_protobuf/proto_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace google {
1919
// Unlike ProtoSetField, this allows setting message, map and repeated fields.
2020
void ProtoInitFields(::google::protobuf::Message* message, kwargs kwargs_in);
2121

22-
// Wrapper around ::google::protobuf::Message::CopyFrom which can efficiently copy from
23-
// either a wrapped C++ or native python proto. Throws an error if `other`
24-
// is not a proto of the correct type.
22+
// Wrapper around ::google::protobuf::Message::CopyFrom which can efficiently
23+
// copy from either a wrapped C++ or native python proto. Throws an error if
24+
// `other` is not a proto of the correct type.
2525
void ProtoCopyFrom(::google::protobuf::Message* msg, handle other);
2626

2727
// Allocate and return the ProtoType given by the template argument.

0 commit comments

Comments
 (0)