https://github.com/python/cpython/commit/8c0c3443f39cd8a7d177516e814082f8bdb46f63
commit: 8c0c3443f39cd8a7d177516e814082f8bdb46f63
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: Yhg1s <tho...@python.org>
date: 2024-09-24T11:34:21-07:00
summary:

[3.13] gh-124120: Document `Annotated.__origin__` (GH-124125) (#124416)

gh-124120: Document `Annotated.__origin__` (GH-124125)
(cherry picked from commit faef3fa653f2901cc905f98eae0ddcd8dc334d33)

Co-authored-by: sobolevn <m...@sobolevn.me>
Co-authored-by: Brian Schubert <brianm.schub...@gmail.com>
Co-authored-by: Alex Waygood <alex.wayg...@gmail.com>

files:
M Doc/library/typing.rst

diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 7f8e246a648190..c158b207bf6195 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -1458,6 +1458,23 @@ These can be used as types in annotations. They all 
support subscription using
         >>> X.__metadata__
         ('very', 'important', 'metadata')
 
+   * At runtime, if you want to retrieve the original
+     type wrapped by ``Annotated``, use the :attr:`!__origin__` attribute:
+
+     .. doctest::
+
+        >>> from typing import Annotated, get_origin
+        >>> Password = Annotated[str, "secret"]
+        >>> Password.__origin__
+        <class 'str'>
+
+     Note that using :func:`get_origin` will return ``Annotated`` itself:
+
+     .. doctest::
+
+        >>> get_origin(Password)
+        typing.Annotated
+
    .. seealso::
 
       :pep:`593` - Flexible function and variable annotations
@@ -3222,6 +3239,7 @@ Introspection helpers
       assert get_origin(str) is None
       assert get_origin(Dict[str, int]) is dict
       assert get_origin(Union[int, str]) is Union
+      assert get_origin(Annotated[str, "metadata"]) is Annotated
       P = ParamSpec('P')
       assert get_origin(P.args) is P
       assert get_origin(P.kwargs) is P

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to