Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Defer to autodoc for signatures #221

Merged
merged 12 commits into from
Jun 27, 2020
Merged
16 changes: 0 additions & 16 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,22 +566,6 @@ def __init__(self, func, role='func', doc=None, config={}):
doc = inspect.getdoc(func) or ''
NumpyDocString.__init__(self, doc, config)

if not self['Signature'] and func is not None:
func, func_name = self.get_func()
try:
try:
signature = str(inspect.signature(func))
except (AttributeError, ValueError):
# try to read signature, backward compat for older Python
if sys.version_info[0] >= 3:
argspec = inspect.getfullargspec(func)
else:
argspec = inspect.getargspec(func)
signature = inspect.formatargspec(*argspec)
signature = '%s%s' % (func_name, signature)
except TypeError:
signature = '%s()' % func_name
self['Signature'] = signature

def get_func(self):
func_name = getattr(self._f, '__name__', self.__class__.__name__)
Expand Down
2 changes: 2 additions & 0 deletions numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
sig = doc['Signature'] or getattr(obj, '__text_signature__', None)
if sig:
sig = re.sub("^[^(]*", "", sig)
sig = re.sub(r"\$self,\s", "", sig)
thequackdaddy marked this conversation as resolved.
Show resolved Hide resolved
sig = re.sub(r"\/,\s", "", sig)
return sig, ''


Expand Down
2 changes: 1 addition & 1 deletion numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def my_func(a, b, **kwargs):
pass

fdoc = FunctionDoc(func=my_func)
assert fdoc['Signature'] == 'my_func(a, b, **kwargs)'
assert fdoc['Signature'] == ''


doc4 = NumpyDocString(
Expand Down
3 changes: 2 additions & 1 deletion numpydoc/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def test_MyClass(sphinx_app):
html = fid.read()
# ensure that no autodoc weirdness ($) occurs
assert '$self' not in html
assert '/,' not in html
assert '__init__' in html # inherited
# escaped * chars should no longer be preceded by \'s,
# if we see a \* in the output we know it's incorrect:
assert r'\*' not in html
# "self" should not be in the parameter list for the class:
assert 'self,' in html # XXX should be "not in", bug!
assert 'self,' not in html
# check xref was embedded properly (dict should link using xref):
assert 'stdtypes.html#dict' in html

Expand Down