Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign updecorated functions #58
Comments
This comment has been minimized.
This comment has been minimized.
|
It seems especially tricky if the decorator returns a callable object instance, not a function. |
This comment has been minimized.
This comment has been minimized.
|
Use |
This comment has been minimized.
This comment has been minimized.
|
Tried using http://stackoverflow.com/questions/6394511/python-functools-wraps-equivalent-for-classes to wrap the class instance. However, pdoc will recognize it as a var, not a function, and still not carry over the docs. |
This comment has been minimized.
This comment has been minimized.
|
Can you please produce a minimal example of your problem? Everything seems to be working fine for me:
|
This comment has been minimized.
This comment has been minimized.
|
Sure, try this:
The resulting docs will list func as a variable and include no docs. |
BurntSushi
added
the
bug
label
Jul 15, 2015
This comment has been minimized.
This comment has been minimized.
|
Interesting. This one may be quite difficult to fix: import functools
class Decorator(object):
def __init__(self, func):
self.f = func
functools.update_wrapper(self, func)
def __call__(self, *args, **kwargs):
return self.f(*args, **kwargs)
@Decorator
def func(a):
"""
Awesome func.
"""
return a
import inspect
for x in filter(lambda s: s.startswith('is'), dir(inspect)):
print(x, getattr(inspect, x)(func))Outputs:
Which means |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
I can't think of anything you can do in your source code. You could patch if inspect.isfunction(obj) or inspect.isbuiltin(obj):
self.doc[name] = Function(name, self, obj)
elif inspect.ismethod(obj):
self.doc[name] = Function(name, self, obj)
elif inspect.isclass(obj):
self.doc[name] = Class(name, self, obj)
elif inspect.ismodule(obj):
# Only document modules that are submodules or are forcefully
# exported by __all__.
if obj is not self.module and \
(self.__is_exported(name, obj)
or self.is_submodule(obj.__name__)):
self.doc[name] = self.__new_submodule(name, obj)
elif name in vardocs:
self.doc[name] = vardocs[name]
elif hasattr(obj, '__call__'):
self.doc[name] = Class(name, self, obj)
else:
# Catch all for variables.
self.doc[name] = Variable(name, self, '', cls=None)The docs don't show because variables don't have
|
This comment has been minimized.
This comment has been minimized.
fritzvd
commented
Jun 27, 2016
|
Hi, I'm running into the same issue, is this being worked on? Or is this an Fritz |
hyukim17 commentedJul 15, 2015
Is there an easy way to allow pdoc to access the doc of decorated functions?
For example, how can I make pdoc document:
@memoize
def func(a, b, c):
"""
Doc string
"""
return a, b, c