From 6bdd58a115765e47945d37af285c18d663cbbcd8 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 11 Jan 2021 16:16:24 -0800 Subject: [PATCH] Adding isinstance in type_caster::load functions. --- tests/test_classh_wip.cpp | 15 ++++++++++----- tests/test_classh_wip.py | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/test_classh_wip.cpp b/tests/test_classh_wip.cpp index f9dc6e57e..9501d514e 100644 --- a/tests/test_classh_wip.cpp +++ b/tests/test_classh_wip.cpp @@ -101,7 +101,8 @@ struct type_caster { operator mpty const*() { return rtrn_mpty_cptr(); } operator mpty*() { return rtrn_mpty_mptr(); } - bool load(handle /*src*/, bool /*convert*/) { + bool load(handle src, bool /*convert*/) { + if (!isinstance(src)) return false; return true; } }; @@ -120,7 +121,8 @@ struct type_caster> { operator std::shared_ptr() { return rtrn_mpty_shmp(); } - bool load(handle /*src*/, bool /*convert*/) { + bool load(handle src, bool /*convert*/) { + if (!isinstance(src)) return false; return true; } }; @@ -139,7 +141,8 @@ struct type_caster> { operator std::shared_ptr() { return rtrn_mpty_shcp(); } - bool load(handle /*src*/, bool /*convert*/) { + bool load(handle src, bool /*convert*/) { + if (!isinstance(src)) return false; return true; } }; @@ -158,7 +161,8 @@ struct type_caster> { operator std::unique_ptr() { return rtrn_mpty_uqmp(); } - bool load(handle /*src*/, bool /*convert*/) { + bool load(handle src, bool /*convert*/) { + if (!isinstance(src)) return false; return true; } }; @@ -177,7 +181,8 @@ struct type_caster> { operator std::unique_ptr() { return rtrn_mpty_uqcp(); } - bool load(handle /*src*/, bool /*convert*/) { + bool load(handle src, bool /*convert*/) { + if (!isinstance(src)) return false; return true; } }; diff --git a/tests/test_classh_wip.py b/tests/test_classh_wip.py index 00eafce08..492f5a2f2 100644 --- a/tests/test_classh_wip.py +++ b/tests/test_classh_wip.py @@ -23,12 +23,12 @@ def test_cast(): def test_load(): - assert m.pass_mpty_valu(None) == "load_valu" - assert m.pass_mpty_rref(None) == "load_rref" - assert m.pass_mpty_cref(None) == "load_cref" - assert m.pass_mpty_mref(None) == "load_mref" - assert m.pass_mpty_cptr(None) == "load_cptr" - assert m.pass_mpty_mptr(None) == "load_mptr" + assert m.pass_mpty_valu(m.mpty()) == "load_valu" + assert m.pass_mpty_rref(m.mpty()) == "load_rref" + assert m.pass_mpty_cref(m.mpty()) == "load_cref" + assert m.pass_mpty_mref(m.mpty()) == "load_mref" + assert m.pass_mpty_cptr(m.mpty()) == "load_cptr" + assert m.pass_mpty_mptr(m.mpty()) == "load_mptr" def test_cast_shared_ptr(): @@ -37,8 +37,8 @@ def test_cast_shared_ptr(): def test_load_shared_ptr(): - assert m.pass_mpty_shmp(None) == "load_shmp" - assert m.pass_mpty_shcp(None) == "load_shcp" + assert m.pass_mpty_shmp(m.mpty()) == "load_shmp" + assert m.pass_mpty_shcp(m.mpty()) == "load_shcp" def test_cast_unique_ptr(): @@ -47,5 +47,5 @@ def test_cast_unique_ptr(): def test_load_unique_ptr(): - assert m.pass_mpty_uqmp(None) == "load_uqmp" - assert m.pass_mpty_uqcp(None) == "load_uqcp" + assert m.pass_mpty_uqmp(m.mpty()) == "load_uqmp" + assert m.pass_mpty_uqcp(m.mpty()) == "load_uqcp"