-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Display typing.Annotated metadata in the Python domain
#11785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Zac-HD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the parameter x: Annotated[int, Ge(0), Lt(10)] (using annotated-types). Rendering this as x: int[Ge(0), Lt(10)] would be absurd.
I therefore think that we should render typing.Annotated types in documentation with f"Annotated[{stringify_annotation(T)}, {', '.join(repr(x) for x in metadata)}].
# Conflicts: # sphinx/util/typing.py
# Conflicts: # CHANGES.rst # tests/test_util/test_util_typing.py
typing.Annotated metadata in the Python domain
|
Thanks all! A |
|
I think I found a regression about this. We're using the CSSClassType = Annotated[str, pydantic.AfterValidator(nodes.make_id)]
class CustomAdmonitionConfig(pydantic.BaseModel):
title: Annotated[Optional[str], pydantic.Field(validate_default=True)] = None
classes: List[CSSClassType] = []But autodoc-ing
I think lesson here is that not all metadata is compatible with autodoc. Is there a way to disable it? |
Subject: Add metadata to Annotated types
Feature or Bugfix
Purpose
This adds metadata to
Annotatedtypes.Detail
Relates
Fixes #11773