Skip to content

Commit

Permalink
pydrake: Commmit selected clang-format results
Browse files Browse the repository at this point in the history
All of these changes were suggested by clang-format, though some other
suggested changes within these same files have been declined.

In a future commit, we will finish up the re-formatting work and enable
the clang-format idempotency linter.
  • Loading branch information
jwnimmer-tri committed Nov 30, 2018
1 parent 337434c commit 653f413
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 436 deletions.
5 changes: 3 additions & 2 deletions bindings/bazel_workaround_4594_libdrake_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ namespace drake {
namespace pydrake {

PYBIND11_MODULE(bazel_workaround_4594_libdrake, m) {
m.doc() = "Consolidated workaround for bazelbuild/bazel#4594 to load "
"libdrake.so, to be used by `pydrake/__init__.py`.";
m.doc() =
"Consolidated workaround for bazelbuild/bazel#4594 to load "
"libdrake.so, to be used by `pydrake/__init__.py`.";
}

} // namespace pydrake
Expand Down
3 changes: 1 addition & 2 deletions bindings/pydrake/common/cpp_param_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ py::object GetPyParamScalarImpl(const std::type_info& tinfo) {
// once simpler dependencies are used (or something else is used to
// justify linking in `libdrake.so`).
const std::string name = tinfo.name();
throw std::runtime_error(
"C++ type is not registered in pybind: " + name);
throw std::runtime_error("C++ type is not registered in pybind: " + name);
}
py::handle h(reinterpret_cast<PyObject*>(info->type));
return py::reinterpret_borrow<py::object>(h);
Expand Down
2 changes: 1 addition & 1 deletion bindings/pydrake/common/cpp_param_pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline py::object GetPyParamScalarImpl(
/// @returns Python tuple of canonical parameters.
/// @throws std::runtime_error on the first type it encounters that is neither
/// aliased nor registered in `pybind11`.
template <typename ... Ts>
template <typename... Ts>
inline py::tuple GetPyParam(type_pack<Ts...> = {}) {
return py::make_tuple(internal::GetPyParamScalarImpl(type_pack<Ts>{})...);
}
Expand Down
15 changes: 5 additions & 10 deletions bindings/pydrake/common/cpp_template_pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ inline void AddInstantiation(
// Gets name for a given instantiation.
inline std::string GetInstantiationName(
py::handle py_template, py::tuple param) {
return py::cast<std::string>(
py_template.attr("_instantiation_name")(param));
return py::cast<std::string>(py_template.attr("_instantiation_name")(param));
}

} // namespace internal


/// Provides a temporary, unique name for a class instantiation that
/// will be passed to `AddTemplateClass`.
template <typename T>
std::string TemporaryClassName(
const std::string& name = "TemporaryName") {
std::string TemporaryClassName(const std::string& name = "TemporaryName") {
return "_" + name + "_" + typeid(T).name();
}

Expand Down Expand Up @@ -100,8 +97,7 @@ py::class_<Class, Options...> DefineTemplateClassWithDefault(
/// @param param Parameters for the instantiation.
template <typename Func>
py::object AddTemplateFunction(
py::handle scope, const std::string& name, Func&& func,
py::tuple param) {
py::handle scope, const std::string& name, Func&& func, py::tuple param) {
// TODO(eric.cousineau): Use `py::sibling` if overloads are needed.
py::object py_template =
internal::GetOrInitTemplate(scope, name, "TemplateFunction");
Expand All @@ -121,9 +117,8 @@ template <typename Method>
py::object AddTemplateMethod(
py::handle scope, const std::string& name, Method&& method,
py::tuple param) {
py::object py_template =
internal::GetOrInitTemplate(
scope, name, "TemplateMethod", py::make_tuple(scope));
py::object py_template = internal::GetOrInitTemplate(
scope, name, "TemplateMethod", py::make_tuple(scope));
py::object py_func = py::cpp_function(
std::forward<Method>(method),
py::name(internal::GetInstantiationName(py_template, param).c_str()),
Expand Down
3 changes: 1 addition & 2 deletions bindings/pydrake/common/deprecation_pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace pydrake {
/// Deprecates an attribute `name` of a class `cls`.
/// This *only* works with class attributes (unbound members or methods) as it
/// is implemented with a Python property descriptor.
inline void DeprecateAttribute(
py::object cls, py::str name, py::str message) {
inline void DeprecateAttribute(py::object cls, py::str name, py::str message) {
py::object deprecated =
py::module::import("pydrake.common.deprecation").attr("deprecated");
py::object original = cls.attr(name);
Expand Down
10 changes: 5 additions & 5 deletions bindings/pydrake/common/drake_optional_pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace detail {
// @see pybind11/stl.h, `optional_caster`.

template <typename T>
struct type_caster<stx::optional<T>> :
public optional_caster<stx::optional<T>> {};
struct type_caster<stx::optional<T>>
: public optional_caster<stx::optional<T>> {};

template<>
struct type_caster<stx::nullopt_t> :
public void_caster<stx::nullopt_t> {};
template <>
struct type_caster<stx::nullopt_t>
: public void_caster<stx::nullopt_t> {};

} // namespace detail
} // namespace pybind11
Expand Down
4 changes: 2 additions & 2 deletions bindings/pydrake/common/drake_variant_pybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace detail {
// @see pybind11/stl.h, `variant_caster`.

template <typename... Types>
struct type_caster<stx::variant<Types...>> :
public variant_caster<stx::variant<Types...>> {};
struct type_caster<stx::variant<Types...>>
: public variant_caster<stx::variant<Types...>> {};

} // namespace detail
} // namespace pybind11
Loading

0 comments on commit 653f413

Please sign in to comment.