AnswerDotAI / AnswerDotAI/fastcore

`show_doc` renders classes with `def` prefix instead of `class`

Open Beginner friendly
#829 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
1.1k
Forks
295
Avg merge
1d 6h
Merged PRs (30d)
7

Description

## `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

```python
def FixSigMeta(
args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

```

### To Reproduce

```python
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

```python
class MyClass(
param1:str, param2:int=10
)
```

### Actual Output

```python
def MyClass(
param1:str, param2:int=10
)
```

### Root Cause

In `fastcore/docments.py` around line 375, the code determines the prefix for the signature:

```python
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

```python
if inspect.isclass(o):
prefix = 'class'
elif inspect.iscoroutinefunction(o):
prefix = 'async def'
else:
prefix = 'def'
```

Contributor guide

Open the contributing guide

Research direction

Start in fastcore/docments.py around line 375, where show_doc-related signature formatting chooses the prefix. Reproduce the issue with the provided show_doc(MyClass) example, then verify the generated signature uses class for classes while preserving the existing function behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.