mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Fail on passing py::object with wrong Python type to py::object subclass using PYBIND11_OBJECT macro (#2349)
* Fail on passing py::object with wrong Python type to py::object subclass using PYBIND11_OBJECT macro * Split off test_non_converting_constructors from test_constructors * Fix test_as_type, as py::type constructor now throws an error itself if the argument is not a type * Replace tp_name access by pybind11::detail::get_fully_qualified_tp_name * Move forward-declaration of get_fully_qualified_tp_name to detail/common.h * Don't add the builtins module name in get_fully_qualified_tp_name for PyPy * Add PYBIND11_BUILTINS_MODULE macro, and use it in get_fully_qualified_tp_name
This commit is contained in:
@@ -245,6 +245,20 @@ def test_constructors():
|
||||
assert noconv2[k] is expected[k]
|
||||
|
||||
|
||||
def test_non_converting_constructors():
|
||||
non_converting_test_cases = [
|
||||
("bytes", range(10)),
|
||||
("none", 42),
|
||||
("ellipsis", 42),
|
||||
]
|
||||
for t, v in non_converting_test_cases:
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
m.nonconverting_constructor(t, v)
|
||||
expected_error = "Object of type '{}' is not an instance of '{}'".format(
|
||||
type(v).__name__, t)
|
||||
assert str(excinfo.value) == expected_error
|
||||
|
||||
|
||||
def test_pybind11_str_raw_str():
|
||||
# specifically to exercise pybind11::str::raw_str
|
||||
cvt = m.convert_to_pybind11_str
|
||||
|
||||
Reference in New Issue
Block a user