Skip to content

Commit de0fbb4

Browse files
committed
Add __dir__ method to Equation and ParameterProxy.
This supports attributes completion in IPython.
1 parent 0707cb8 commit de0fbb4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

diffpy/srfit/equation/equationmod.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ def __getattr__(self, name):
116116
raise AttributeError("No argument named '%s' here" % name)
117117
return argdict[name]
118118

119+
120+
# Ensure there is no __dir__ override in the base class.
121+
assert (getattr(Operator, '__dir__', None) is
122+
getattr(object, '__dir__', None))
123+
124+
125+
def __dir__(self):
126+
"Return sorted list of attributes for this object."
127+
rv = set(dir(type(self)))
128+
rv.update(self.__dict__.keys() + self.argdict.keys())
129+
rv = sorted(rv)
130+
return rv
131+
132+
119133
def setRoot(self, root):
120134
"""Set the root of the Literal tree.
121135

diffpy/srfit/fitbase/parameter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ def __getattr__(self, attrname):
170170
par = object.__getattribute__(self, 'par')
171171
return getattr(par, attrname)
172172

173+
174+
# Ensure there is no __dir__ override in the base classes.
175+
assert (getattr(_parameter_interface, '__dir__', None) is
176+
getattr(Validatable, '__dir__', None) is
177+
getattr(object, '__dir__', None))
178+
179+
180+
def __dir__(self):
181+
"Return sorted list of attributes for this object."
182+
rv = set(dir(type(self)))
183+
rv.update(self.__dict__.keys() + dir(self.par))
184+
rv = sorted(rv)
185+
return rv
186+
187+
173188
value = property( lambda self: self.par.getValue(),
174189
lambda self, val: self.par.setValue(val) )
175190

0 commit comments

Comments
 (0)