laike9m / pdir2

Pretty dir() printing with joy:beer:
MIT License
1.33k stars 47 forks source link

Set empty doc if testing for __doc__ attribute throws an exception. #57

Closed Mome closed 2 years ago

Mome commented 2 years ago

I was getting an error when I tried to run pdir on classes from a jar-file wrapped with jpype:

~/.local/lib/python3.9/site-packages/pdir/api.py in get_oneline_doc(self)
    205             return ', '.join(doc_list)
    206 
--> 207         if hasattr(attr, '__doc__'):
    208             doc = inspect.getdoc(attr)
    209             return doc.split('\n', 1)[0] if doc else ''  # default doc is None

~/.local/lib/python3.9/site-packages/jpype/_jclass.py in _jclassDoc(cls)
    162     if not hasattr(cls, "__javadoc__"):
    163         jde = JClass("org.jpype.javadoc.JavadocExtractor")()
--> 164         jd = jde.getDocumentation(cls)
    165         if jd is not None:
    166             setattr(cls, "__javadoc__", jd)

SystemError: Fail in conversion

In this fix I simply set an empty doc if an Exception occurs calling hasattr.

laike9m commented 2 years ago

Hi, Thanks for the PR! Could you add a test case for it?

Mome commented 2 years ago

Was not so easy to fabricate the problem, but I guess that's a proper test case.

laike9m commented 2 years ago

Thanks!