From 87c34fa9ae2a179d1849e585b7e5acad76cb8733 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 16 Apr 2024 13:53:56 +0200 Subject: [PATCH] Get rid of amici.swig_wrappers.ExpData The old implementation prevented using e.g. `isinstance(x, amici.ExpData)`. Closes #2380 --- python/sdist/amici/swig_wrappers.py | 27 --------------------------- swig/edata.i | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/python/sdist/amici/swig_wrappers.py b/python/sdist/amici/swig_wrappers.py index e942cc76dd..4e4ca3a5b1 100644 --- a/python/sdist/amici/swig_wrappers.py +++ b/python/sdist/amici/swig_wrappers.py @@ -18,7 +18,6 @@ __all__ = [ "runAmiciSimulation", "runAmiciSimulations", - "ExpData", "readSolverSettingsFromHDF5", "writeSolverSettingsToHDF5", "set_model_settings", @@ -128,32 +127,6 @@ def runAmiciSimulation( return numpy.ReturnDataView(rdata) -def ExpData(*args) -> "amici_swig.ExpData": - """ - Convenience wrapper for :py:class:`amici.amici.ExpData` constructors - - :param args: arguments - - :returns: ExpData Instance - """ - if not args: - return amici_swig.ExpData() - - if isinstance(args[0], numpy.ReturnDataView): - return amici_swig.ExpData(_get_ptr(args[0]["ptr"]), *args[1:]) - - if isinstance(args[0], (amici_swig.ExpData, amici_swig.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 amici_swig.ExpData(_get_ptr(args[0]), *args[1:]) - - if isinstance(args[0], (amici_swig.Model, amici_swig.ModelPtr)): - return amici_swig.ExpData(_get_ptr(args[0])) - - return amici_swig.ExpData(*args) - - def runAmiciSimulations( model: AmiciModel, solver: AmiciSolver, diff --git a/swig/edata.i b/swig/edata.i index f2f7d0da8a..b2becd6f8d 100644 --- a/swig/edata.i +++ b/swig/edata.i @@ -72,6 +72,32 @@ 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) + + if isinstance(args[0], numpy.ReturnDataView): + return super().__new__(cls, _get_ptr(args[0]["ptr"]), *args[1:]) + + if isinstance(args[0], (amici_swig.ExpData, amici_swig.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], (amici_swig.Model, amici_swig.ModelPtr)): + return super().__new__(cls, _get_ptr(args[0])) + + return super().__new__(cls, *args) + + def __repr__(self): return _edata_repr(self)