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 @@ -1458,6 +1458,23 @@ These can be used as types in annotations. They all support subscription using
1458
1458
>>> X.__metadata__
1459
1459
('very', 'important', 'metadata')
1460
1460
1461
+ * At runtime, if you want to retrieve the original
1462
+ type wrapped by ``Annotated ``, use the :attr: `!__origin__ ` attribute:
1463
+
1464
+ .. doctest ::
1465
+
1466
+ >>> from typing import Annotated, get_origin
1467
+ >>> Password = Annotated[str , " secret" ]
1468
+ >>> Password.__origin__
1469
+ <class 'str'>
1470
+
1471
+ Note that using :func: `get_origin ` will return ``Annotated `` itself:
1472
+
1473
+ .. doctest ::
1474
+
1475
+ >>> get_origin(Password)
1476
+ typing.Annotated
1477
+
1461
1478
.. seealso ::
1462
1479
1463
1480
:pep: `593 ` - Flexible function and variable annotations
@@ -3298,6 +3315,7 @@ Introspection helpers
3298
3315
assert get_origin(str) is None
3299
3316
assert get_origin(Dict[str, int]) is dict
3300
3317
assert get_origin(Union[int, str]) is Union
3318
+ assert get_origin(Annotated[str, "metadata"]) is Annotated
3301
3319
P = ParamSpec('P')
3302
3320
assert get_origin(P.args) is P
3303
3321
assert get_origin(P.kwargs) is P
You can’t perform that action at this time.
0 commit comments