help#
Provides tools to build an interactive, searchable help based on docstrings.
Any class to decorated with @add_help
gets a help() method that provides an interactive and searchable help
based on the method docstrings. All public methods (not starting with “_”)
are added, together with all such methods in all the members that are
classes decorated with @add_help. Derived classes inherit the help system
without a need to use the @add_help decorator.
Help is built dynamically when invoked, so if a new member is added to the class at runtime, it will appear in the help too.
The help method name can be customized giving the help_function parameter
to the decorator.
If the classmethod parameter is True, the help function is created
as a classmethod instead of an ordinary method. This is useful
for classes that only define classmethods and are not normally instanced.
Example:
from arte.utils.help import add_help
@add_help
class InnerClass():
"""An inner class"""
def a_method(self):
"""This is a method"""
pass
@add_help
class MyClass():
"""This is my class"""
b = InnerClass()
def a_method(self):
"""This is a method"""
pass
def another_method(self):
"""This is another method"""
pass
@add_help(help_function='show_help')
class CustomClass():
"""This a custom class"""
def a_method(self):
"""This is a method"""
pass
Interactive session:
>>> a = MyClass()
>>> a.help()
---------
MyClass This is my class
MyClass.a_method() This is a method
MyClass.another_method() This is another method
---------
MyClass.b An inner class
MyClass.b.a_method() This is a method
>>> a.help('other')
---------
MyClass.another_method() This is another method
>>> a.help('inner')
---------
MyClass.b An inner class
>>> b = CustomClass()
>>> b.show_help()
---------
CustomClass This a custom class
CustomClass.a_method() This is a method
- arte.utils.help.add_help(cls=None, *, help_function='help', classmethod=False)#
Decorator to add interactive help to a class
- Parameters:
help_function (str, optional) – Name of the method that will be added to the class. Defaults to “help”
classmethod (bool, optional) – If True, the help method will be added as a classmethod. Default False
- Returns:
The decorated class type
- Return type:
class
- arte.utils.help.hide_from_help(f)#
Decorator to hide a method from the interactive help
- arte.utils.help.modify_help(call=None, arg_str=None, doc_str=None)#
Decorator to modify the automatic help for a method.
Without this decorator, the method signature for help is just “method()”. Using this decorator, other signatures are possible:
@modify_help(call='mymethod1(foo)') def mymethod1(self, ....) """This method is very cool""" @modify_help(arg_str='idx1, idx2') def mymethod2(self, ....) """Now you see it""" @modify_help(doc_str='Surprise!') def mymethod3(self, ....) """And now you don't"""
Resulting help:
.mymethod1(foo) : This method is very cool .mymethod2(idx1, idx2) : Now you see it .mymethod3() : Surprise!
Note
if the method is a @staticmethod, this decorator should be inserted after the staticmethod one.