From 7a514ef32d36f41dbad319f19eb5460cb3ce4ca4 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 20 Aug 2021 14:03:37 +0200 Subject: [PATCH 1/4] bpo-44926: `get_type_hints`: add note about type aliases with forward refs --- Doc/library/typing.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index e8d7c9ee01bd1f5..d48fd5677adb456 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2013,6 +2013,14 @@ Introspection helpers 'name': Annotated[str, 'some marker'] } + .. note:: + + :func:`get_type_hints` does not work reliably with :ref:`type aliases ` that include + forward references. + When type aliases are imported into other modules, their forward references are + not evaluated in the namespace they were originally declared in. + Consider avoiding forward references by enabling postponed evaluation of annotations (:pep:`563`) instead. + .. versionchanged:: 3.9 Added ``include_extras`` parameter as part of :pep:`593`. From 0aacfcfe159f4faf640ef72149cbddde339b4c54 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 20 Aug 2021 14:04:45 +0200 Subject: [PATCH 2/4] bpo-44926: `get_type_hints`: shorten note on type aliases --- Doc/library/typing.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index d48fd5677adb456..95665c3f91f3dd5 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2015,10 +2015,8 @@ Introspection helpers .. note:: - :func:`get_type_hints` does not work reliably with :ref:`type aliases ` that include + :func:`get_type_hints` does not work with imported :ref:`type aliases ` that include forward references. - When type aliases are imported into other modules, their forward references are - not evaluated in the namespace they were originally declared in. Consider avoiding forward references by enabling postponed evaluation of annotations (:pep:`563`) instead. .. versionchanged:: 3.9 From a5ab063e6af70bfcf61853ef216ae33811841cb8 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 20 Aug 2021 14:52:49 +0200 Subject: [PATCH 3/4] incorporate @Fidget-Spinner's suggestion Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 95665c3f91f3dd5..2756aa04cd3794a 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2017,7 +2017,7 @@ Introspection helpers :func:`get_type_hints` does not work with imported :ref:`type aliases ` that include forward references. - Consider avoiding forward references by enabling postponed evaluation of annotations (:pep:`563`) instead. + Enabling postponed evaluation of annotations (:pep:`563`) may remove the need for most forward references. .. versionchanged:: 3.9 Added ``include_extras`` parameter as part of :pep:`593`. From 6f0b0445c73eb7da3b511aaee82ad605d6423650 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 20 Aug 2021 14:55:38 +0200 Subject: [PATCH 4/4] fix max line length --- Doc/library/typing.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 2756aa04cd3794a..47d6c3a2e389851 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2015,9 +2015,10 @@ Introspection helpers .. note:: - :func:`get_type_hints` does not work with imported :ref:`type aliases ` that include - forward references. - Enabling postponed evaluation of annotations (:pep:`563`) may remove the need for most forward references. + :func:`get_type_hints` does not work with imported + :ref:`type aliases ` that include forward references. + Enabling postponed evaluation of annotations (:pep:`563`) may remove + the need for most forward references. .. versionchanged:: 3.9 Added ``include_extras`` parameter as part of :pep:`593`.