Returns the underlying annotation and any metadata from typing.Annotated.
(annotation: Any)
| 188 | |
| 189 | |
| 190 | def _strip_annotated(annotation: Any) -> tuple[Any, tuple[Any, ...]]: |
| 191 | """Returns the underlying annotation and any metadata from typing.Annotated.""" |
| 192 | |
| 193 | metadata: tuple[Any, ...] = () |
| 194 | ann = annotation |
| 195 | |
| 196 | while get_origin(ann) is Annotated: |
| 197 | args = get_args(ann) |
| 198 | if not args: |
| 199 | break |
| 200 | ann = args[0] |
| 201 | metadata = (*metadata, *args[1:]) |
| 202 | |
| 203 | return ann, metadata |
| 204 | |
| 205 | |
| 206 | def _extract_description_from_metadata(metadata: tuple[Any, ...]) -> str | None: |