Skip to content

Commit

Permalink
dir
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Dec 18, 2023
1 parent 50cebd4 commit cd18a22
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions python/sdist/amici/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import collections
import copy
import itertools
from typing import Dict, Iterator, List, Literal, Union

import amici
Expand Down Expand Up @@ -91,15 +92,6 @@ def __init__(self, swigptr):
self._cache = {}
super(SwigPtrView, self).__init__()

# create properties for all fields
for field in self._field_names:
if field not in dir(self):
setattr(
self.__class__,
field,
property(lambda self_: self_.__getitem__(field)),
)

def __len__(self) -> int:
"""
Returns the number of available keys/fields
Expand Down Expand Up @@ -173,6 +165,13 @@ def __eq__(self, other):
return False
return self._swigptr == other._swigptr

def __dir__(self):
return sorted(
set(
itertools.chain(dir(super()), self.__dict__, self._field_names)
)
)


class ReturnDataView(SwigPtrView):
"""
Expand Down Expand Up @@ -297,7 +296,7 @@ def __init__(self, rdata: Union[ReturnDataPtr, ReturnData]):
"numerrtestfailsB": [rdata.nt],
"numnonlinsolvconvfailsB": [rdata.nt],
}
super(ReturnDataView, self).__init__(rdata)
super().__init__(rdata)

def __getitem__(
self, item: str
Expand Down Expand Up @@ -415,7 +414,7 @@ def __init__(self, edata: Union[ExpDataPtr, ExpData]):
edata.observedDataStdDev = edata.getObservedDataStdDev()
edata.observedEvents = edata.getObservedEvents()
edata.observedEventsStdDev = edata.getObservedEventsStdDev()
super(ExpDataView, self).__init__(edata)
super().__init__(edata)


def _field_as_numpy(
Expand Down

0 comments on commit cd18a22

Please sign in to comment.