| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 996e409 commit 0c36c37
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1405,6 +1405,23 @@ These can be used as types in annotations. They all support subscription using | |||
| 1405 | 1405 | >>> X.__metadata__ | |
| 1406 | 1406 | ('very', 'important', 'metadata') | |
| 1407 | 1407 | ||
| 1408 | + * At runtime, if you want to retrieve the original | ||
| 1409 | + type wrapped by ``Annotated``, use the :attr:`!__origin__` attribute: | ||
| 1410 | + | ||
| 1411 | + .. doctest:: | ||
| 1412 | + | ||
| 1413 | + >>> from typing import Annotated, get_origin | ||
| 1414 | + >>> Password = Annotated[str, "secret"] | ||
| 1415 | + >>> Password.__origin__ | ||
| 1416 | + <class 'str'> | ||
| 1417 | + | ||
| 1418 | + Note that using :func:`get_origin` will return ``Annotated`` itself: | ||
| 1419 | + | ||
| 1420 | + .. doctest:: | ||
| 1421 | + | ||
| 1422 | + >>> get_origin(Password) | ||
| 1423 | + <class 'typing.Annotated'> | ||
| 1424 | + | ||
| 1408 | 1425 | .. seealso:: | |
| 1409 | 1426 | ||
| 1410 | 1427 | :pep:`593` - Flexible function and variable annotations | |
@@ -3010,6 +3027,7 @@ Introspection helpers | |||
| 3010 | 3027 | assert get_origin(str) is None | |
| 3011 | 3028 | assert get_origin(Dict[str, int]) is dict | |
| 3012 | 3029 | assert get_origin(Union[int, str]) is Union | |
| 3030 | + assert get_origin(Annotated[str, "metadata"]) is Annotated | ||
| 3013 | 3031 | P = ParamSpec('P') | |
| 3014 | 3032 | assert get_origin(P.args) is P | |
| 3015 | 3033 | assert get_origin(P.kwargs) is P | |
| Back | FazBrowse Home | New Git URL |
0 commit comments