From 70e470b0a59a4bc32cad50ced72829fb1277e942 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 10 Nov 2014 22:37:16 +0000 Subject: [PATCH] fiddle with pyvips8 docstrings --- TODO | 15 ++++++++++++++- python/Vips.py | 13 ++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 69e1f3c6..49e581ae 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,20 @@ - can we generate python docstrings? - when we make a __getattr__ object, make it respond to __doc__ + this works + + help(Vips.Image.black) + + but this does not + + help(Vips.Image.add) + + since add is an instance method ... this does work + + a = Vips.Image.black(10, 10) + help(a.add) + + do we need to override __getattribute__ as well? - test other arg types diff --git a/python/Vips.py b/python/Vips.py index 3f4d2b00..351f9805 100644 --- a/python/Vips.py +++ b/python/Vips.py @@ -418,7 +418,11 @@ class Image(Vips.Image): if name in dir(self.props): return getattr(self.props, name) - return lambda *args, **kwargs: _call_instance(self, name, args, kwargs) + def call_function(*args, **kwargs): + return _call_instance(self, name, args, kwargs) + call_function.__doc__ = "hello world, from " + name + + return call_function def __add__(self, other): if isinstance(other, Vips.Image): @@ -747,8 +751,15 @@ class_methods = [ "fitsload", "openexrload"] +def add_doc(value): + def _doc(func): + func.__doc__ = value + return func + return _doc + def generate_class_method(name): @classmethod + @add_doc('hello, world!') def class_method(cls, *args, **kwargs): return _call_base(name, args, kwargs)