pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.14k stars 146 forks source link

ForwardRef not unwrapped for inner quoted types in arguments #327

Open Terrance opened 3 years ago

Terrance commented 3 years ago

Expected behavior

ForwardRef wrappers to be removed from argument type annotations, as per 8702f62.

Actual behavior

For arguments, the wrapper is removed only if the entire type is quoted. When a quoted reference forms part of a larger type (e.g. Optional["MyClass"]), the wrapper persists in the formatted annotation.

Return types are however correctly parsed in either style.

Example

from typing import Optional

def all_quoted(arg: "Optional[MyClass]") -> "Optional[MyClass]":
    pass

def min_quoted(arg: Optional["MyClass"]) -> Optional["MyClass"]:
    pass

This produces the following, with ForwardRef wrapping the argument to min_quoted but not its return type:

Functions

all_quoted(arg: Optional[MyClass]) ‑> Optional[MyClass]

min_quoted(arg: Optional[ForwardRef('MyClass')]) ‑> Optional[MyClass]

Additional info