Add is_final to disallow inheritance from Python
- Not currently supported on PyPy
diff --git a/tests/test_class.cpp b/tests/test_class.cpp
index 499d0cc..128bc39 100644
--- a/tests/test_class.cpp
+++ b/tests/test_class.cpp
@@ -367,6 +367,14 @@
.def(py::init<>())
.def("ptr", &Aligned::ptr);
#endif
+
+ // test_final
+ struct IsFinal final {};
+ py::class_<IsFinal>(m, "IsFinal", py::is_final());
+
+ // test_non_final_final
+ struct IsNonFinalFinal {};
+ py::class_<IsNonFinalFinal>(m, "IsNonFinalFinal", py::is_final());
}
template <int N> class BreaksBase { public: virtual ~BreaksBase() = default; };
diff --git a/tests/test_class.py b/tests/test_class.py
index ed63ca8..e58fef6 100644
--- a/tests/test_class.py
+++ b/tests/test_class.py
@@ -279,3 +279,21 @@
if hasattr(m, "Aligned"):
p = m.Aligned().ptr()
assert p % 1024 == 0
+
+
+# https://bitbucket.org/pypy/pypy/issues/2742
+@pytest.unsupported_on_pypy
+def test_final():
+ with pytest.raises(TypeError) as exc_info:
+ class PyFinalChild(m.IsFinal):
+ pass
+ assert str(exc_info.value).endswith("is not an acceptable base type")
+
+
+# https://bitbucket.org/pypy/pypy/issues/2742
+@pytest.unsupported_on_pypy
+def test_non_final_final():
+ with pytest.raises(TypeError) as exc_info:
+ class PyNonFinalFinalChild(m.IsNonFinalFinal):
+ pass
+ assert str(exc_info.value).endswith("is not an acceptable base type")