Skip to content

Commit

Permalink
Add SwigPtrView 's fields as properties
Browse files Browse the repository at this point in the history
This way, `dir(SwigPtrView(...))` will show the available fields
and sufficiently smart IDEs will show them for code completion.
  • Loading branch information
dweindl committed Dec 17, 2023
1 parent 594b07e commit 9496671
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/sdist/amici/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9496671

Please sign in to comment.