sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Better rendering of Annotated types

Open dstansby opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. For classes that have a __class_getitem__() method that returns an Annotated type, the extra metadata stored on the Annotated object is not rendered in the type hints in sphinx docs.

Describe the solution you'd like Extra metadata is included in rendered type hints.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Minimal example that builds is at https://github.com/dstansby/quantity-typing-docs/tree/c69c2a8c86314ef672d4484072067888c2627ac7 The code and rendered docs are below:

from typing import Annotated

__all__ = ["deg2rad"]

class A:
    def __class_getitem__(cls, t: type):
        return Annotated[cls, t]


def deg2rad(arg: A[str]) -> A[bytes]:
    return A()

Screenshot 2023-11-28 at 13 30 51

Note how only the class A is shown. Ideally I would like the type hint to read A[str].

Possibly related to https://github.com/sphinx-doc/sphinx/pull/9590

dstansby avatar Nov 28 '23 13:11 dstansby