diff --git a/include/aidge/utils/DynamicAttributes.hpp b/include/aidge/utils/DynamicAttributes.hpp index 2e87f41f6ac972b9e2d59ecabbcf80df4340cc6e..cfacc6b3bd02040b4b7cabc776ed3779852f18fc 100644 --- a/include/aidge/utils/DynamicAttributes.hpp +++ b/include/aidge/utils/DynamicAttributes.hpp @@ -127,7 +127,18 @@ public: { mAnyCompare.emplace(std::make_pair<std::type_index, bool(*)(const future_std::any&, const future_std::any&)>(typeid(T), [](const future_std::any& lhs, const future_std::any& rhs) { - return (future_std::any_cast<T>(lhs) < future_std::any_cast<T>(rhs)); +#ifdef PYBIND + if (lhs.type() == typeid(py::object)) { + return (future_std::any_cast<py::object>(lhs).cast<T>() < future_std::any_cast<T>(rhs)); + } + else if (rhs.type() == typeid(py::object)) { + return (future_std::any_cast<T>(lhs) < future_std::any_cast<py::object>(rhs).cast<T>()); + } + else +#endif + { + return (future_std::any_cast<T>(lhs) < future_std::any_cast<T>(rhs)); + } })); const auto dot = name.find('.'); diff --git a/src/utils/DynamicAttributes.cpp b/src/utils/DynamicAttributes.cpp index 56731f234cec303c4b5329d69634a7e4589236d3..cbcd872b613b5b6fc38bbdc82c73a554c46bb43b 100644 --- a/src/utils/DynamicAttributes.cpp +++ b/src/utils/DynamicAttributes.cpp @@ -14,7 +14,18 @@ std::map<std::type_index, bool(*)(const future_std::any&, const future_std::any&)> Aidge::DynamicAttributes::mAnyCompare; bool future_std::operator<(const future_std::any& lhs, const future_std::any& rhs) { - return (lhs.type() == rhs.type()) - ? Aidge::DynamicAttributes::mAnyCompare.at(lhs.type())(lhs, rhs) - : (lhs.type().before(rhs.type())); + if (lhs.type() == rhs.type()) { + return Aidge::DynamicAttributes::mAnyCompare.at(lhs.type())(lhs, rhs); + } +#ifdef PYBIND + else if (lhs.type() == typeid(py::object)) { + return Aidge::DynamicAttributes::mAnyCompare.at(rhs.type())(lhs, rhs); + } + else if (rhs.type() == typeid(py::object)) { + return Aidge::DynamicAttributes::mAnyCompare.at(rhs.type())(lhs, rhs); + } +#endif + else { + return (lhs.type().before(rhs.type())); + } }