diff --git a/swig/edata.i b/swig/edata.i index d3d19b76c8..47332dbbf2 100644 --- a/swig/edata.i +++ b/swig/edata.i @@ -8,6 +8,22 @@ using namespace amici; %ignore ConditionContext; +%feature("pythonprepend") ExpData::ExpData %{ + """ + Convenience wrapper for :py:class:`amici.amici.ExpData` constructors + + :param args: arguments + + :returns: ExpData Instance + """ + if args: + from amici.numpy import ReturnDataView + + # Get the raw pointer if necessary + if isinstance(args[0], (ExpData, ExpDataPtr, ReturnDataView, Model, ModelPtr)): + args[0] = _get_ptr(args[0]["ptr"]) +%} + // ExpData.__repr__ %pythoncode %{ def _edata_repr(self: "ExpData"): @@ -72,34 +88,6 @@ def _edata_repr(self: "ExpData"): %} %extend amici::ExpData { %pythoncode %{ -def __new__(cls, *args, **kwargs): - """ - Convenience wrapper for :py:class:`amici.amici.ExpData` constructors - - :param args: arguments - - :returns: ExpData Instance - """ - if not args: - return super().__new__(cls) - - from amici.numpy import ReturnDataView - - if isinstance(args[0], ReturnDataView): - return super().__new__(cls, _get_ptr(args[0]["ptr"]), *args[1:]) - - if isinstance(args[0], (ExpData, ExpDataPtr)): - # the *args[:1] should be empty, but by the time you read this, - # the constructor signature may have changed, and you are glad this - # wrapper did not break. - return super().__new__(cls, _get_ptr(args[0]), *args[1:]) - - if isinstance(args[0], (Model, ModelPtr)): - return super().__new__(cls, _get_ptr(args[0])) - - return super().__new__(cls, *args) - - def __repr__(self): return _edata_repr(self)