Skip to content

Commit

Permalink
adding custom __dir__() methods to remove name and parent attributes …
Browse files Browse the repository at this point in the history
…form the tab-to-complete list
  • Loading branch information
awalter-bnl committed Jun 26, 2024
1 parent 841b1b6 commit 29c708b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Binary file modified src/ari_sxn_common/__pycache__/common_bluesky.cpython-312.pyc
Binary file not shown.
43 changes: 43 additions & 0 deletions src/ari_sxn_common/common_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class PlanCollectorSub:
Returns a user friendly formatted string showing the structure of the
instance including all of the methods from methods_to_import but not
the 'name' or 'parent' attributes.
__dir__() :
Returns a list of attribute name strings to be used to define what
options are available when doing tab-to-complete.
"""
def __init__(self, methods_to_import, name, parent):
for plan_name, function in methods_to_import.items():
Expand Down Expand Up @@ -85,6 +88,25 @@ def __str__(self):

return output

def __dir__(self):
"""
Used to limit the number of options when using tab to complete.
This method is used to give the list of options when using pythons tab
to complete process. It gives all of the method attributes but not the
'name' and 'parent' attributes.
Returns
-------
attribute_list : list[str]
A list of attribute names to be included when using tab-to-complete
"""
attribute_list = [plan for plan in self.__dict__.keys()
if plan not in ['name', 'parent']]

return attribute_list



class PlanCollector:
"""
Expand Down Expand Up @@ -140,6 +162,9 @@ class PlanCollector:
instance including all of the methods from plans_to_import,
plan_stubs_to_import and any PlanCollectorSub attributes but not the
'name' attribute.
__dir__() :
Returns a list of attribute name strings to be used to define what
options are available when doing tab-to-complete.
"""
def __init__(self, plans_to_import, plan_stubs_to_import, name):
"""
Expand Down Expand Up @@ -213,3 +238,21 @@ def __str__(self):
output += f'\n {name}'

return output

def __dir__(self):
"""
Used to limit the number of options when using tab to complete.
This method is used to give the list of options when using pythons tab
to complete process. It gives all of the method attributes and any
PlanCollectorSun attributes but not the 'name' attribute.
Returns
-------
attribute_list : list[str]
A list of attribute names to be included when using tab-to-complete
"""
attribute_list = [plan for plan in self.__dict__.keys()
if plan not in ['name']]

return attribute_list

0 comments on commit 29c708b

Please sign in to comment.