diff --git a/bindings/pybind11_ext/numpy_dtypes_user.h b/bindings/pybind11_ext/numpy_dtypes_user.h index 629342b3ea5b..1341881d82ec 100644 --- a/bindings/pybind11_ext/numpy_dtypes_user.h +++ b/bindings/pybind11_ext/numpy_dtypes_user.h @@ -466,16 +466,16 @@ class dtype_user : public object { } /// Defines a constructor. - template + template dtype_user& def( - detail::initimpl::constructor&&, const char* doc = "") { + detail::initimpl::constructor&&, Extra&&... extra) { // See notes in `add_init`. // N.B. Do NOT use `Class*` as the argument, since that may incur recursion. add_init([](object py_self, Args... args) { // Old-style. No factories for now. Class* self = DTypePyObject::load_raw(py_self.ptr()); new (self) Class(std::forward(args)...); - }, doc); + }, detail::type_pack{}, std::forward(extra)...); return *this; } @@ -607,8 +607,8 @@ class dtype_user : public object { } // Adds constructor. See comments within for explanation. - template - void add_init(Func&& f, const char* doc) { + template + void add_init(Func&& f, detail::type_pack, Extra&&... extra) { // Do not construct this with the name `__init__` as `pybind11`s // constructor implementations via `cpp_function` are rigidly fixed to // its instance registration system (which we don't want). @@ -620,10 +620,10 @@ class dtype_user : public object { if (!d.contains("__init__")) { auto init = self().attr("_dtype_init"); auto func = cpp_function( - [init](handle self, args args, kwargs kwargs) { + [init](handle self, Args... args) { // Dispatch. - init(self, *args, **kwargs); - }, is_method(self()), doc); + init(self, std::forward(args)...); + }, is_method(self()), std::forward(extra)...); self().attr("__init__") = func; } } diff --git a/bindings/pydrake/symbolic_py.cc b/bindings/pydrake/symbolic_py.cc index 62ea6ce03fec..363f32f446fc 100644 --- a/bindings/pydrake/symbolic_py.cc +++ b/bindings/pydrake/symbolic_py.cc @@ -61,8 +61,9 @@ PYBIND11_MODULE(symbolic, m) { var_doc.Type.RANDOM_EXPONENTIAL.doc); var_cls - .def(py::init(), py::arg("name"), - py::arg("type") = Variable::Type::CONTINUOUS, var_doc.ctor.doc_2args) + .def(py::init(), + py::arg("name"), py::arg("type") = Variable::Type::CONTINUOUS, + var_doc.ctor.doc_2args) .def("get_id", &Variable::get_id, var_doc.get_id.doc) .def("get_type", &Variable::get_type, var_doc.get_type.doc) .def("__str__", &Variable::to_string, var_doc.to_string.doc) @@ -209,7 +210,7 @@ PYBIND11_MODULE(symbolic, m) { expr_cls // BR .def(py::init<>(), doc.Expression.ctor.doc_0args) .def(py::init(), doc.Expression.ctor.doc_1args_d) - .def(py::init(), doc.Expression.ctor.doc_copy) + .def(py::init(), doc.Expression.ctor.doc_1args_var) // Casting .def_loop(py::dtype_method::implicit_conversion()) // Methods