From 841a575e1a9ce80d291fe900a0904a16344212b9 Mon Sep 17 00:00:00 2001 From: "Cristofaro, Marco" Date: Mon, 2 Mar 2026 11:19:33 +0100 Subject: [PATCH 1/3] Fix SwigPyObject look-up --- include/swigbind11/swigbind11.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/swigbind11/swigbind11.hpp b/include/swigbind11/swigbind11.hpp index ad5d284..1cca009 100644 --- a/include/swigbind11/swigbind11.hpp +++ b/include/swigbind11/swigbind11.hpp @@ -35,8 +35,12 @@ inline auto extract_swig_object(py::handle obj, std::string_view type_name) { // obj is a proxy object generated by SWIG, we need to extract the underlying SWIG object auto swig_obj = obj.attr("this"); - const auto type = py::str(py::type::of(swig_obj)).cast(); - if (type != "") { + const std::string type_str = py::str(py::type::of(swig_obj)).cast(); + + // look for "SwigPyObject" in name + // type_str = (SWIG < 4.4.0) + // type_str = (SWIG >= 4.4.0) + if (type_str.find("SwigPyObject") == std::string::npos) { throw py::cast_error{"expected SWIG-wrapped object, got: " + type}; } From bce3cc3934e255ea16efc2245dc0ec4d00830633 Mon Sep 17 00:00:00 2001 From: "Cristofaro, Marco" Date: Mon, 2 Mar 2026 11:19:51 +0100 Subject: [PATCH 2/3] Remove max swig version requirement --- example/pyproject.toml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/pyproject.toml b/example/pyproject.toml index e2af40b..49f200d 100644 --- a/example/pyproject.toml +++ b/example/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ "scikit-build-core", - "swig<4.4.0", + "swig", "pybind11", ] # Use a custom in-tree backend to inject local dependencies. diff --git a/pyproject.toml b/pyproject.toml index ccfef63..740b8b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = ["scikit-build-core", - "swig<4.4.0", + "swig", "setuptools-scm" ] build-backend = "scikit_build_core.build" From 1b04c617ec968549b6639b061b8e328a13a303bc Mon Sep 17 00:00:00 2001 From: jain_ra Date: Tue, 3 Mar 2026 11:32:34 +0100 Subject: [PATCH 3/3] corrected: type does not exits --- include/swigbind11/swigbind11.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/swigbind11/swigbind11.hpp b/include/swigbind11/swigbind11.hpp index 1cca009..fe5b1f8 100644 --- a/include/swigbind11/swigbind11.hpp +++ b/include/swigbind11/swigbind11.hpp @@ -41,7 +41,7 @@ inline auto extract_swig_object(py::handle obj, std::string_view type_name) { // type_str = (SWIG < 4.4.0) // type_str = (SWIG >= 4.4.0) if (type_str.find("SwigPyObject") == std::string::npos) { - throw py::cast_error{"expected SWIG-wrapped object, got: " + type}; + throw py::cast_error{"expected SWIG-wrapped object, got: " + type_str}; } return swig_obj;