show_doc renders classes with def prefix instead of class
Description
When using show_doc() (from nbdev) on a Python class, the generated documentation incorrectly shows the class signature with def instead of class.
This problem can be seen in the fastcore documentation itself:
https://fastcore.fast.ai/meta.html#fixsigmeta
...which incorrectly displays
def FixSigMeta(
args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):
To Reproduce
from nbdev.showdoc import show_doc
class MyClass:
def __init__(self, param1: str, param2: int = 10):
"""A simple class"""
self.param1 = param1
self.param2 = param2
show_doc(MyClass)
Expected Output
class MyClass(
param1:str, param2:int=10
)
Actual Output
def MyClass(
param1:str, param2:int=10
)
Root Cause
In fastcore/docments.py around line 375, the code determines the prefix for the signature:
prefix = 'async def' if inspect.iscoroutinefunction(o) else 'def'
This checks for async functions but always defaults to 'def' for everything else, including classes. It never checks inspect.isclass(o) to use 'class' as the prefix.
Suggested Fix
if inspect.isclass(o):
prefix = 'class'
elif inspect.iscoroutinefunction(o):
prefix = 'async def'
else:
prefix = 'def'
show_docrenders classes withdefprefix instead ofclassDescription
When using
show_doc()(from nbdev) on a Python class, the generated documentation incorrectly shows the class signature withdefinstead ofclass.This problem can be seen in the
fastcoredocumentation itself:https://fastcore.fast.ai/meta.html#fixsigmeta
...which incorrectly displays
To Reproduce
Expected Output
Actual Output
Root Cause
In
fastcore/docments.pyaround line 375, the code determines the prefix for the signature:This checks for async functions but always defaults to
'def'for everything else, including classes. It never checksinspect.isclass(o)to use'class'as the prefix.Suggested Fix