File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines 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
14051405 >>> X.__metadata__
14061406 ('very', 'important', 'metadata')
14071407
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+
14081425 .. seealso ::
14091426
14101427 :pep: `593 ` - Flexible function and variable annotations
@@ -3010,6 +3027,7 @@ Introspection helpers
30103027 assert get_origin(str) is None
30113028 assert get_origin(Dict[str, int]) is dict
30123029 assert get_origin(Union[int, str]) is Union
3030+ assert get_origin(Annotated[str, "metadata"]) is Annotated
30133031 P = ParamSpec('P')
30143032 assert get_origin(P.args) is P
30153033 assert get_origin(P.kwargs) is P
You can’t perform that action at this time.
0 commit comments