Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DocWrap(object):
- '''
- This class provides a simple base class for wrapper objects around opaque,
- undocumented blobs. Instances should provide custom doc strings to make their opaque
- contents appear as a documented Python object.
- '''
- def __init__(self, obj, docstr):
- '''
- initialise DocWrap object with given opaque instance and docstring for it.
- '''
- self.__instance__ = obj
- self.__doc__ = docstr
- def __setattr_(self, name, value):
- if name == '__instance__':
- object.__setattr__(self, name, value)
- else:
- object.__setattr__(self.__instance__, name, value)
- def __getattribute__(self, name):
- if name == '__doc__':
- return object.__getattribute__(self, name)
- elif name == '__instance__':
- return object.__getattribute__(self, name)
- else:
- return object.__getattribute__(self.__instance__, name)
- test= DocWrap(object(), 'hello world!')
- ex = DocWrap(Exception(), 'some other type for comparison of dir() output')
- print(test.__doc__) # should appear as 'hello world!'
- print(dir(test))
- print(dir(ex))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement