From 94966711bd8405bc9971c3440f51ef878d1061fd Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Sun, 17 Dec 2023 17:52:36 +0100 Subject: [PATCH] Add SwigPtrView 's fields as properties This way, `dir(SwigPtrView(...))` will show the available fields and sufficiently smart IDEs will show them for code completion. --- python/sdist/amici/numpy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/sdist/amici/numpy.py b/python/sdist/amici/numpy.py index b84e52cc2b..3449a19642 100644 --- a/python/sdist/amici/numpy.py +++ b/python/sdist/amici/numpy.py @@ -91,6 +91,13 @@ def __init__(self, swigptr): self._cache = {} super(SwigPtrView, self).__init__() + # create properties for all fields + for field in self._field_names: + if not hasattr(self.__class__, field): + setattr( + self.__class__, field, property(lambda self: self[field]) + ) + def __len__(self) -> int: """ Returns the number of available keys/fields