Skip to content

Warning (and mildly inelegant output) from pdoc when using a type defined using a type alias #822

@wgmo

Description

@wgmo

Problem Description

Using a type defined using a type alias produces a warning message and uses ForwardRef('TheType') in documentation output instead of the correct TheType.

Sample code:

from __future__ import annotations

from typing import NamedTuple

import numpy
from numpy.typing import NDArray

type Array = NDArray[numpy.float64]


class ArrayThing(NamedTuple):
    data: Array

This triggers the following warning when running pdoc:

$ PDOC_ALLOW_EXEC=1 uv run --quiet --locked pdoc -d google -o docs --math foo
Warn: Error parsing type annotation ForwardRef('Array') for foo.foo.ArrayThing.__init__. Import of Array failed: name 'Array' is not defined (/home/me/pdoc_test/.venv/lib/python3.13/site-packages/pdoc/doc_types.py:148)

The output is usable but slightly verbose (it includes the ForwardRef instead of directly naming the type which has been defined:

Image

Steps to reproduce the behavior:

  1. Run pdoc on the python source defined above!

System Information

$ PDOC_ALLOW_EXEC=1 uv run --quiet --locked pdoc -d google -o docs --math --version
pdoc: 15.0.4
Python: 3.13.1
Platform: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.36

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions