AnswerDotAI / AnswerDotAI/fastcore

Docment renderers collapse parameterized annotations to their unparameterized type

Open Beginner friendly
#910 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

Docment-based signature rendering loses type parameters from generic annotations.

For example, `list[str]` is rendered as `list`, and `tuple[str, int]` is rendered as `tuple`.

## Reproduction

```python
from fastcore.docments import sig2str

def f(
items:list[str],
) -> tuple[str, int]:
pass

print(sig2str(f))
```

Actual output:

```python
def f(
items:list
)->tuple:
```

Expected output:

```python
def f(
items:list[str]
)->tuple[str,int]:
```

## Environment

- fastcore: 2.2.13
- Branch: `main`

## Scope

The issue affects multiple docment renderers, including:

- `DocmentText`
- `DocmentList`
- `DocmentTbl`

## Likely cause

The renderers use `_maybe_nm()` for annotations:

```python
def _maybe_nm(o):
if o == inspect._empty: return ''
return o.__name__ if hasattr(o, '__name__') else str(o)
```

Parameterized generic aliases expose the unparameterized origin through `__name__`:

```python
tuple[str, int].__name__
# 'tuple'
```

By comparison, annotation-aware formatting preserves the parameters:

```python
inspect.formatannotation(tuple[str, int])
# 'tuple[str, int]'
```

Annotation formatting should preserve generic parameters without changing the existing formatting of ordinary classes or default values.

Contributor guide

Open the contributing guide

Research direction

Start in fastcore.docments at _maybe_nm() and trace how DocmentText, DocmentList, and DocmentTbl format annotations for sig2str. Run the supplied reproduction with list[str] and tuple[str, int], then verify that generic parameters are preserved while ordinary classes and default values retain their existing formatting.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.