mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Make attr and item accessors throw on error instead of returning nullptr
This also adds the `hasattr` and `getattr` functions which are needed with the new attribute behavior. The new functions behave exactly like their Python counterparts. Similarly `object` gets a `contains` method which calls `__contains__`, i.e. it's the same as the `in` keyword in Python.
This commit is contained in:
@@ -39,7 +39,7 @@ PYBIND11_PLUGIN(pybind11_tests) {
|
||||
for (const auto &initializer : initializers())
|
||||
initializer(m);
|
||||
|
||||
if (!m.attr("have_eigen")) m.attr("have_eigen") = py::cast(false);
|
||||
if (!py::hasattr(m, "have_eigen")) m.attr("have_eigen") = py::cast(false);
|
||||
|
||||
return m.ptr();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user