Skip to content

Commit a6dc2aa

Browse files
committed
fixes #796
1 parent 317b4dc commit a6dc2aa

2 files changed

Lines changed: 129 additions & 45 deletions

File tree

fastcore/docments.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from io import BytesIO
1515
from textwrap import dedent
1616
from types import SimpleNamespace
17-
from inspect import getsource,isfunction,ismethod,isclass,signature,Parameter
17+
from inspect import getsource,isfunction,ismethod,isclass,signature,Parameter,Signature
1818
from dataclasses import dataclass, is_dataclass
1919
from .utils import *
2020
from .meta import delegates
@@ -157,7 +157,7 @@ def docments(s, full=False, eval_str=False, returns=True, args_kwargs=False):
157157
"Get docments for `s`"
158158
if isclass(s) and not is_dataclass(s): s = s.__init__
159159
try: sig = signature_ex(s, eval_str=eval_str)
160-
except ValueError: return AttrDict()
160+
except (ValueError, TypeError): return AttrDict()
161161
nps = parse_docstring(s)
162162
docs = {}
163163
while s:
@@ -347,6 +347,7 @@ def _fmt_default(o):
347347
if o is empty: return ''
348348
return o.__name__ if hasattr(o, '__name__') else repr(o)
349349

350+
# %% ../nbs/04_docments.ipynb #7f5e5282
350351
class DocmentText(_DocmentBase):
351352
def __init__(self, obj, maxline=110, docstring=True):
352353
super().__init__(obj)
@@ -370,7 +371,7 @@ def __str__(self):
370371
o = self.obj
371372
is_inst = callable(o) and not (isfunction(o) or isclass(o) or inspect.isbuiltin(o) or ismethod(o))
372373
prefix = 'async def' if inspect.iscoroutinefunction(o) else 'def'
373-
nm = f'{type(o).__name__}.__call__' if is_inst else get_name(o)
374+
nm = get_name(o) if hasattr(o, '__name__') else f'{type(o).__name__}.__call__' if is_inst else get_name(o)
374375
if (sig := _clean_text_sig(o)) and not self.params: sig_str = f"{prefix} {sig}"
375376
else: sig_str = _fmt_sig(nm, self.params, self._ret_str, self.maxline, prefix=prefix)
376377
doc = getattr(o.__call__, '__doc__', None) if is_inst else o.__doc__

0 commit comments

Comments
 (0)