Skip to content

Commit 6871511

Browse files
committed
Add __dir__ method to the RecipeContainer class.
This improves IPython completion for FitRecipe objects.
1 parent de0fbb4 commit 6871511

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

diffpy/srfit/fitbase/recipeorganizer.py

+18
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ def __getattr__(self, name):
147147
raise AttributeError(name)
148148
return arg
149149

150+
151+
# Ensure there is no __dir__ override in the base class.
152+
assert (getattr(Observable, '__dir__', None) is
153+
getattr(Configurable, '__dir__', None) is
154+
getattr(Validatable, '__dir__', None) is
155+
getattr(object, '__dir__', None))
156+
157+
def __dir__(self):
158+
"Return sorted list of attributes for this object."
159+
rv = set(dir(type(self)))
160+
rv.update(self.__dict__.keys())
161+
# self.get fetches looks up for items in all managed dictionaries.
162+
# Add keys from each dictionary in self.__managed.
163+
rv.update(*self.__managed)
164+
rv = sorted(rv)
165+
return rv
166+
167+
150168
# Needed by __setattr__
151169
_parameters = {}
152170
__managed = {}

0 commit comments

Comments
 (0)