sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Fix rendering of nested type annotations with alias defined

Open JanLuca opened this issue 4 years ago • 1 comments

Subject: Fix rendering of nested type annotations with alias defined

Feature or Bugfix

  • Bugfix

Purpose

  • Make autodoc usable with nested types with alias defined

Detail

The current implementation replaces type annotations with a alias defined by the class TypeAliasForwardRef. This class is later again replaced by the type defined in the alias map.

This commit fixes the problem that this second replacement does not happen if the aliased type is nested in another generic type (e.g. Iterator[aliased_type]). The new function goes recursivly through the nested types and replaces the internal class TypeAliasForwardRef again by the correct annotation.

Relates

JanLuca avatar Oct 14 '21 16:10 JanLuca

I've been getting the error unhashable type: 'TypeAliasForwardRef' with nitpicky=True with certain types of nested type hints. This PR makes them go away.

(side question: is it possible to tell autodoc to just completely not try to make type hints into cross-references?)

asmeurer avatar Feb 08 '22 06:02 asmeurer