From 2acc4345a25537d549c73deeb4986cba59abaefa Mon Sep 17 00:00:00 2001 From: Alper Yoney Date: Thu, 26 Dec 2024 15:56:47 -0800 Subject: [PATCH] Apply clang-tidy to thrift/lib/py3 Summary: - [modernize-concat-nested-namespaces](https://clang.llvm.org/extra/clang-tidy/checks/modernize/concat-nested-namespaces.html) - [modernize-use-override](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-override.html) (only 1 change) - [modernize-use-using](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-using.html) (only 1 change) Reviewed By: createdbysk Differential Revision: D67655278 fbshipit-source-id: 191a06d9b11f2bea07c088e681274c251b9125f7 --- thrift/lib/py3/client.h | 6 ++---- thrift/lib/py3/client_wrapper.h | 6 ++---- thrift/lib/py3/exceptions.h | 8 ++------ thrift/lib/py3/serializer.h | 6 ++---- thrift/lib/py3/server.h | 8 +++----- thrift/lib/py3/stream.cpp | 7 +++---- thrift/lib/py3/stream.h | 6 ++---- thrift/lib/py3/test/BinaryTypes.h | 8 +++----- thrift/lib/py3/test/cpp_handler.h | 8 ++------ thrift/lib/py3/test/interactions/interaction_test.h | 8 ++------ thrift/lib/py3/test/is_overload/func.h | 8 ++------ thrift/lib/py3/types.h | 6 ++---- 12 files changed, 27 insertions(+), 58 deletions(-) diff --git a/thrift/lib/py3/client.h b/thrift/lib/py3/client.h index 0bd81d444ce..9c36eaa152b 100644 --- a/thrift/lib/py3/client.h +++ b/thrift/lib/py3/client.h @@ -31,8 +31,7 @@ #include #include -namespace thrift { -namespace py3 { +namespace thrift::py3 { using RequestChannel_ptr = apache::thrift::RequestChannel::Ptr; /* @@ -51,5 +50,4 @@ inline void destroyInEventBaseThread(RequestChannel_ptr&& ptr) { eb->runInEventBaseThread([ptr = std::move(ptr)] {}); } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 diff --git a/thrift/lib/py3/client_wrapper.h b/thrift/lib/py3/client_wrapper.h index 487b0bf8c05..34838bb9a47 100644 --- a/thrift/lib/py3/client_wrapper.h +++ b/thrift/lib/py3/client_wrapper.h @@ -23,8 +23,7 @@ #include #include -namespace thrift { -namespace py3 { +namespace thrift::py3 { class ClientWrapper { protected: @@ -57,5 +56,4 @@ class ClientWrapper { } }; -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 diff --git a/thrift/lib/py3/exceptions.h b/thrift/lib/py3/exceptions.h index 5ca0d4a2359..73d2127e5a6 100644 --- a/thrift/lib/py3/exceptions.h +++ b/thrift/lib/py3/exceptions.h @@ -21,9 +21,7 @@ #include -namespace thrift { -namespace py3 { -namespace exception { +namespace thrift::py3::exception { // The only place this function is used it needs a shared_ptr, so may as // well just return one instead of a unique_ptr @@ -34,6 +32,4 @@ std::shared_ptr try_make_shared_exception( return e ? std::make_shared(*e) : std::shared_ptr(); } -} // namespace exception -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3::exception diff --git a/thrift/lib/py3/serializer.h b/thrift/lib/py3/serializer.h index 8fe03e1a4fe..0c2113d2f18 100644 --- a/thrift/lib/py3/serializer.h +++ b/thrift/lib/py3/serializer.h @@ -19,8 +19,7 @@ #include #include -namespace thrift { -namespace py3 { +namespace thrift::py3 { using apache::thrift::protocol::PROTOCOL_TYPES; template std::unique_ptr serialize(const T* obj, PROTOCOL_TYPES protocol) { @@ -71,5 +70,4 @@ size_t deserialize(const folly::IOBuf* buf, T* obj, PROTOCOL_TYPES protocol) { LOG(FATAL) << "Bad serialization protocol " << uint8_t(protocol); } } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 diff --git a/thrift/lib/py3/server.h b/thrift/lib/py3/server.h index 1f3a5707bb3..66fa2e64e4a 100644 --- a/thrift/lib/py3/server.h +++ b/thrift/lib/py3/server.h @@ -24,8 +24,7 @@ #include #include -namespace thrift { -namespace py3 { +namespace thrift::py3 { using AddressHandler = folly::Function; template @@ -45,7 +44,7 @@ class Py3ServerEventHandler folly::Executor* executor, AddressHandler address_handler) : executor_(executor), address_handler_(std::move(address_handler)) {} - void preServe(const folly::SocketAddress* address) { + void preServe(const folly::SocketAddress* address) override { executor_->add([addr = *address, this]() mutable { address_handler_(std::move(addr)); }); @@ -66,5 +65,4 @@ inline std::string getRequestId() { return {}; } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 diff --git a/thrift/lib/py3/stream.cpp b/thrift/lib/py3/stream.cpp index 7a795c1d50e..3f8518c910c 100644 --- a/thrift/lib/py3/stream.cpp +++ b/thrift/lib/py3/stream.cpp @@ -23,8 +23,7 @@ #if __has_include() && FOLLY_HAS_COROUTINES #include // @manual -namespace thrift { -namespace py3 { +namespace thrift::py3 { namespace { @@ -41,6 +40,6 @@ void cancelPythonIterator(PyObject* iter) { cancelAsyncGenerator(iter); } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 + #endif diff --git a/thrift/lib/py3/stream.h b/thrift/lib/py3/stream.h index 07ca30e0da2..2d17e4ea687 100644 --- a/thrift/lib/py3/stream.h +++ b/thrift/lib/py3/stream.h @@ -33,8 +33,7 @@ #if FOLLY_HAS_COROUTINES -namespace thrift { -namespace py3 { +namespace thrift::py3 { template class ClientBufferedStreamWrapper { @@ -122,8 +121,7 @@ apache::thrift::ServerStream createAsyncIteratorFromPyIterator( } }); } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3 #else /* !FOLLY_HAS_COROUTINES */ #error Thrift stream type support needs C++ coroutines, which are not currently available. \ diff --git a/thrift/lib/py3/test/BinaryTypes.h b/thrift/lib/py3/test/BinaryTypes.h index 611518996e9..b3c909e9f80 100644 --- a/thrift/lib/py3/test/BinaryTypes.h +++ b/thrift/lib/py3/test/BinaryTypes.h @@ -69,13 +69,12 @@ class Buffer : boost::totally_ordered { } // namespace test -namespace apache { -namespace thrift { +namespace apache::thrift { template <> class Cpp2Ops { public: - typedef test::Buffer Type; + using Type = test::Buffer; static constexpr protocol::TType thriftType() { return protocol::T_STRING; } template static uint32_t write(Protocol* prot, const Type* value) { @@ -95,5 +94,4 @@ class Cpp2Ops { } }; -} // namespace thrift -} // namespace apache +} // namespace apache::thrift diff --git a/thrift/lib/py3/test/cpp_handler.h b/thrift/lib/py3/test/cpp_handler.h index 364ef11f0d5..2b0f3cc42d5 100644 --- a/thrift/lib/py3/test/cpp_handler.h +++ b/thrift/lib/py3/test/cpp_handler.h @@ -19,9 +19,7 @@ #include #include -namespace thrift { -namespace py3 { -namespace test { +namespace thrift::py3::test { class TestingService : public apache::thrift::ServiceHandler { @@ -38,6 +36,4 @@ class TestingService } }; -} // namespace test -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3::test diff --git a/thrift/lib/py3/test/interactions/interaction_test.h b/thrift/lib/py3/test/interactions/interaction_test.h index db12ce4f1a3..ead95af3c80 100644 --- a/thrift/lib/py3/test/interactions/interaction_test.h +++ b/thrift/lib/py3/test/interactions/interaction_test.h @@ -17,9 +17,7 @@ #include #include -namespace interactions { -namespace test { -namespace thrift { +namespace interactions::test::thrift { struct SemiCalculatorHandler : apache::thrift::ServiceHandler { struct SemiAdditionHandler : apache::thrift::ServiceHandler::AdditionIf { @@ -60,6 +58,4 @@ struct SemiCalculatorHandler : apache::thrift::ServiceHandler { }; struct SemiBlankServiceHandler : apache::thrift::ServiceHandler {}; -} // namespace thrift -} // namespace test -} // namespace interactions +} // namespace interactions::test::thrift diff --git a/thrift/lib/py3/test/is_overload/func.h b/thrift/lib/py3/test/is_overload/func.h index 2412043063e..cccf3504803 100644 --- a/thrift/lib/py3/test/is_overload/func.h +++ b/thrift/lib/py3/test/is_overload/func.h @@ -19,9 +19,7 @@ #include #include -namespace thrift { -namespace py3 { -namespace test { +namespace thrift::py3::test { bool isOverloaded( const apache::thrift::transport::THeader::StringToStringMap& /* headers */, @@ -38,6 +36,4 @@ bool checkOverload( // otherwise, it will return no value return ret.hasValue(); } -} // namespace test -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3::test diff --git a/thrift/lib/py3/types.h b/thrift/lib/py3/types.h index d07948a91d4..ae748f03323 100644 --- a/thrift/lib/py3/types.h +++ b/thrift/lib/py3/types.h @@ -30,8 +30,7 @@ #include #include -namespace thrift { -namespace py3 { +namespace thrift::py3 { template std::shared_ptr constant_shared_ptr(const T& x) { @@ -184,5 +183,4 @@ PyObject* init_unicode_from_cpp(const T& str) { return PyUnicode_FromStringAndSize(str.data(), str.size()); } -} // namespace py3 -} // namespace thrift +} // namespace thrift::py3