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.
diff --git a/tests/pybind11_tests.cpp b/tests/pybind11_tests.cpp
index f3f557a..35981a0 100644
--- a/tests/pybind11_tests.cpp
+++ b/tests/pybind11_tests.cpp
@@ -39,7 +39,7 @@
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();
}