8000 Allow optional return (no print) for `.help()`. · ii0/plotly.py@3a14140 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a14140

Browse files
committed
Allow optional return (no print) for .help().
1 parent dd29405 commit 3a14140

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,21 @@ def _get_class_name(self):
8888
"""For convenience. See `graph_reference.object_name_to_class_name`."""
8989
return graph_reference.object_name_to_class_name(self._name)
9090

91-
def help(self):
92-
"""Print a help string for this object."""
91+
def help(self, return_help=False):
92+
"""
93+
Print a help string for this object.
94+
95+
:param (bool) return_help: Return help string instead of prining?
96+
:return: (None|str) Optionally can return help string.
97+
98+
"""
9399
object_name = self._name
94100
path = self._get_path()
95101
parent_object_names = self._get_parent_object_names()
96102
help_string = graph_objs_tools.get_help(object_name, path,
97103
parent_object_names)
104+
if return_help:
105+
return help_string
98106
print(help_string)
99107

100108
def to_graph_objs(self, **kwargs):
@@ -540,18 +548,27 @@ def _value_to_graph_object(self, key, value, _raise=True):
540548
return GraphObjectFactory.create(key, value, _raise=_raise,
541549
_parent=self, _parent_key=key)
542550

543-
def help(self, attribute=None):
544-
"""Print help string for this object or an attribute of this object."""
551+
def help(self, attribute=None, return_help=False):
552+
"""
553+
Print help string for this object or an attribute of this object.
554+
555+
:param (str) attribute: A valid attribute string for this object.
556+
:param (bool) return_help: Return help_string instead of printing it?
557+
:return: (None|str)
558+
559+
"""
545560
if not attribute:
546-
super(PlotlyDict, self).help()
547-
else:
548-
object_name = self._name
549-
path = self._get_path()
550-
parent_object_names = self._get_parent_object_names()
551-
help_string = graph_objs_tools.get_help(object_name, path,
552-
parent_object_names,
553-
attribute)
554-
print(help_string)
561+
return super(PlotlyDict, self).help(return_help=return_help)
562+
563+
object_name = self._name
564+
path = self._get_path()
565+
parent_object_names = self._get_parent_object_names()
566+
help_string = graph_objs_tools.get_help(object_name, path,
567+
parent_object_names, attribute)
568+
569+
if return_help:
570+
return help_string
571+
print(help_string)
555572

556573
def update(self, dict1=None, **dict2):
557574
"""

0 commit comments

Comments
 (0)
0