pymel.util.LazyDocString

digraph inheritance64cc2da24f {
rankdir=TB;
ranksep=0.15;
nodesep=0.15;
size="8.0, 12.0";
  "LazyDocString" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="../pymel.util.utilitytypes/pymel.util.utilitytypes.LazyDocString.html#pymel.util.utilitytypes.LazyDocString",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
}

class LazyDocString(argList)

Set the __doc__ of an object to an object of this class in order to have a docstring that is dynamically generated when used.

Due to restrictions of inheriting from StringType (which is necessary, as the ‘help’ function does a check to see if __doc__ is a string), the creator can only take a single object.

Since the object initialization requires multiple parameters, the LazyDocString should be fed an sliceable-iterable on creation, of the following form:

LazyDocString( [documentedObj, docGetter, arg1, arg2, ...] )

documentedObj should be the object on which we are placing the docstring

docGetter should be a function which is used to retrieve the ‘real’ docstring - it’s args will be documentedObj and any extra args passed to the object on creation.

Example Usage:

>>> def getDocStringFromDict(obj):
...     returnVal = docStringDict[obj]
...     return returnVal
>>> 
>>> # In order to alter the doc of a class, we need to use a metaclass
>>> class TestMetaClass(type): pass
>>>         
>>> class TestClass(object):
...     __metaclass__ = TestMetaClass
... 
...     def aMethod(self):
...         pass
... 
...     aMethod.__doc__ = LazyDocString( (aMethod, getDocStringFromDict, (aMethod,)) )
>>> 
>>> TestClass.__doc__ = LazyDocString( (TestClass, getDocStringFromDict, (TestClass,)) )
>>> 
>>> 
>>> docStringDict = {TestClass:'New Docs for PynodeClass!',
...                  TestClass.aMethod.im_func:'Method docs!'}
>>> 
>>> TestClass.__doc__
'New Docs for PynodeClass!'
>>> TestClass.aMethod.__doc__
'Method docs!'

Note that new-style classes (ie, instances of ‘type’) and instancemethods can’t have their __doc__ altered.

In the case of classes, you can get around this by using a metaclass for the class whose docstring you wish to alter.

In the case of instancemethods, just set the __doc__ on the function underlying the method (ie, myMethod.im_func). Note that if the __doc__ for the method is set within the class definition itself, you will already automatically be modifying the underlying function.

capitalize(*args, **kwargs)
center(*args, **kwargs)
count(*args, **kwargs)
decode(*args, **kwargs)
encode(*args, **kwargs)
endswith(*args, **kwargs)
expandtabs(*args, **kwargs)
find(*args, **kwargs)
format(*args, **kwargs)
index(*args, **kwargs)
isalnum(*args, **kwargs)
isalpha(*args, **kwargs)
isdigit(*args, **kwargs)
islower(*args, **kwargs)
isspace(*args, **kwargs)
istitle(*args, **kwargs)
isupper(*args, **kwargs)
join(*args, **kwargs)
ljust(*args, **kwargs)
lower(*args, **kwargs)
lstrip(*args, **kwargs)
partition(*args, **kwargs)
replace(*args, **kwargs)
rfind(*args, **kwargs)
rindex(*args, **kwargs)
rjust(*args, **kwargs)
rpartition(*args, **kwargs)
rsplit(*args, **kwargs)
rstrip(*args, **kwargs)
split(*args, **kwargs)
splitlines(*args, **kwargs)
startswith(*args, **kwargs)
strip(*args, **kwargs)
swapcase(*args, **kwargs)
title(*args, **kwargs)
translate(*args, **kwargs)
upper(*args, **kwargs)
zfill(*args, **kwargs)

Previous topic

pymel.util.KeysView

Next topic

pymel.util.Mapping

Core

Core Modules

Other Modules

This Page