From 5a5ff4d75ee6ad5ccb325e58a8735f696ca69f63 Mon Sep 17 00:00:00 2001 From: Dominik1123 <> Date: Thu, 12 Nov 2020 21:23:49 +0100 Subject: [PATCH 1/4] bpo-42317: Improve docs of typing.get_args concerning Union --- Doc/library/typing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 9a993c073277f9..41fb12cc8ee160 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1706,6 +1706,8 @@ Introspection helpers For a typing object of the form ``X[Y, Z, ...]`` these functions return ``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or :mod:`collections` class, it gets normalized to the original class. + If ``X`` is a :class:`Union`, the order of ``(Y, Z, ...)`` may be different + from the order of the original arguments ``[Y, Z, ...]``. For unsupported objects return ``None`` and ``()`` correspondingly. Examples:: From adc974db25c52a77a53ac82321e5cd1da9ea0235 Mon Sep 17 00:00:00 2001 From: Dominik1123 <> Date: Fri, 13 Nov 2020 00:09:35 +0100 Subject: [PATCH 2/4] Revert "bpo-42317: Improve docs of typing.get_args concerning Union" This reverts commit 5a5ff4d75ee6ad5ccb325e58a8735f696ca69f63. --- Doc/library/typing.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 41fb12cc8ee160..9a993c073277f9 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1706,8 +1706,6 @@ Introspection helpers For a typing object of the form ``X[Y, Z, ...]`` these functions return ``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or :mod:`collections` class, it gets normalized to the original class. - If ``X`` is a :class:`Union`, the order of ``(Y, Z, ...)`` may be different - from the order of the original arguments ``[Y, Z, ...]``. For unsupported objects return ``None`` and ``()`` correspondingly. Examples:: From 633e73689d1d0bf47d7199492d0b8a3f469e9123 Mon Sep 17 00:00:00 2001 From: Dominik1123 <> Date: Fri, 13 Nov 2020 00:12:56 +0100 Subject: [PATCH 3/4] bpo-42317: Improve docs of typing.get_args concerning generic types --- Doc/library/typing.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 9a993c073277f9..84f3563ff890a0 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1706,6 +1706,9 @@ Introspection helpers For a typing object of the form ``X[Y, Z, ...]`` these functions return ``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or :mod:`collections` class, it gets normalized to the original class. + If ``X`` is a generic type, the returned objects ``(Y, Z, ...)`` + might not be identical to the ones used in the form ``X[Y, Z, ...]`` + due to type caching. For unsupported objects return ``None`` and ``()`` correspondingly. Examples:: From e910d7f26eee6a9a4a9bc01a912d70ee695b6643 Mon Sep 17 00:00:00 2001 From: Dominik1123 <> Date: Fri, 13 Nov 2020 14:16:34 +0100 Subject: [PATCH 4/4] bpo-42317: Improve docs of typing.get_args concerning Unions and generic types --- Doc/library/typing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 84f3563ff890a0..a8de984a5ce41b 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1706,9 +1706,9 @@ Introspection helpers For a typing object of the form ``X[Y, Z, ...]`` these functions return ``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or :mod:`collections` class, it gets normalized to the original class. - If ``X`` is a generic type, the returned objects ``(Y, Z, ...)`` - might not be identical to the ones used in the form ``X[Y, Z, ...]`` - due to type caching. + If ``X`` is a :class:`Union` contained in another generic type, + the order of ``(Y, Z, ...)`` may be different from the order of + the original arguments ``[Y, Z, ...]`` due to type caching. For unsupported objects return ``None`` and ``()`` correspondingly. Examples::