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/include/swigbind11/swigbind11.hpp b/include/swigbind11/swigbind11.hpp index ad5d284..fe5b1f8 100644 --- a/include/swigbind11/swigbind11.hpp +++ b/include/swigbind11/swigbind11.hpp @@ -35,9 +35,13 @@ 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 != "") { - throw py::cast_error{"expected SWIG-wrapped object, got: " + 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_str}; } return swig_obj; 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"