@@ -20,79 +20,83 @@ def get_help(object_name, path=(), parent_object_names=(), attribute=None):
2020 :return: (str) A printable string to show to users.
2121
2222 """
23- help_string = 'Help for {}\n \n ' .format (object_name )
2423 if object_name in graph_reference .ARRAYS :
25- help_string + = _list_help (object_name , path , parent_object_names )
24+ help_string = _list_help (object_name , path , parent_object_names )
2625 else :
2726 if attribute :
28- help_string + = _dict_attribute_help (object_name , path ,
29- parent_object_names , attribute )
27+ help_string = _dict_attribute_help (object_name , path ,
28+ parent_object_names , attribute )
3029 else :
31- help_string += _dict_object_help (object_name , path ,
32- parent_object_names )
33- help_string = help_string .expandtabs (TAB_SIZE )
34- return help_string
30+ help_string = _dict_object_help (object_name , path ,
31+ parent_object_names )
32+ return help_string .expandtabs (TAB_SIZE )
3533
3634
3735def _list_help (object_name , path = (), parent_object_names = ()):
36+ """See get_help()."""
3837 items = graph_reference .ARRAYS [object_name ]['items' ]
3938 items_classes = [graph_reference .string_to_class_name (item )
4039 for item in items ]
41- lines = textwrap .wrap (repr (items_classes ), width = LINE_SIZE - TAB_SIZE )
42- items_string = '\n \t ' .join (lines )
43- help_string = 'Valid Item Classes:\n {}\n ' .format (items_string )
44- return help_string
40+ lines = textwrap .wrap (repr (items_classes ), width = LINE_SIZE - TAB_SIZE )
41+
42+ help_dict = {
43+ 'object_name' : object_name ,
44+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
45+ 'parent_object_names' : parent_object_names ,
46+ 'items_string' : '\t ' + '\n \t ' .join (lines )
47+ }
48+
49+ return (
50+ "Valid items for '{object_name}' at path {path_string} under parents "
51+ "{parent_object_names}:\n {items_string}\n " .format (** help_dict )
52+ )
4553
4654
4755def _dict_object_help (object_name , path , parent_object_names ):
48- """
49- Get general help information on an dict-like plotly graph object.
50-
51- :param object_name:
52- :param path:
53- :param parent_object_names:
54- :return:
55-
56- """
57- parent_class_names = [
58- graph_reference .string_to_class_name (parent_object_name )
59- for parent_object_name in parent_object_names
60- ]
56+ """See get_help()."""
6157 attributes = graph_reference .get_valid_attributes (object_name ,
6258 parent_object_names )
63- help_dict = {'path' : path ,
64- 'parent_class_names' : parent_class_names }
65-
66- lines = textwrap .wrap (repr (list (attributes )), width = LINE_SIZE - TAB_SIZE )
67- attributes_str = '\n \t ' .join (lines )
68- help_string = (
69- "Run `.help('attribute')` on any of the following attributes:\n \n \t "
70- "{attributes_str}"
59+ lines = textwrap .wrap (repr (list (attributes )), width = LINE_SIZE - TAB_SIZE )
60+
61+ help_dict = {
62+ 'object_name' : object_name ,
63+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
64+ 'parent_object_names' : parent_object_names ,
65+ 'attributes_string' : '\t ' + '\n \t ' .join (lines )
66+ }
67+
68+ return (
69+ "Valid attributes for '{object_name}' at path {path_string} under "
70+ "parents {parent_object_names}:\n \n {attributes_string}\n \n "
71+ "Run `<{object_name}-object>.help('attribute')` on any of the above.\n "
72+ "'<{object_name}-object>' is the object at {path_string}"
73+ .format (** help_dict )
7174 )
72- return help_string .format (attributes_str = attributes_str , ** help_dict )
7375
7476
7577def _dict_attribute_help (object_name , path , parent_object_names , attribute ):
7678 """
7779 Get general help information or information on a specific attribute.
7880
81+ See get_help().
82+
7983 :param (str|unicode) attribute: The attribute we'll get info for.
8084
8185 """
82- parent_class_names = [
83- graph_reference .string_to_class_name (parent_object_name )
84- for parent_object_name in parent_object_names
85- ]
86+ help_dict = {
87+ 'object_name' : object_name ,
88+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
89+ 'parent_object_names' : parent_object_names ,
90+ 'attribute' : attribute
91+ }
92+
8693 valid_attributes = graph_reference .get_valid_attributes (
8794 object_name , parent_object_names
8895 )
89- help_dict = {'path' : path ,
90- 'parent_class_names' : parent_class_names ,
91- 'attribute' : attribute }
9296
9397 help_string = (
94- "Current path: {path }\n "
95- "Current parents : {parent_class_names }\n \n " )
98+ "Current path: {path_string }\n "
99+ "Current parent object_names : {parent_object_names }\n \n " )
96100
97101 if attribute not in valid_attributes :
98102 help_string += "'{attribute}' is not allowed here.\n "
0 commit comments