From e039dbc59681e9a94af179ca6d747fe6e6431acf Mon Sep 17 00:00:00 2001 From: Andreas Hangauer Date: Fri, 11 Feb 2022 20:53:05 +0100 Subject: [PATCH 1/3] bpo-46333: include `module` in `ForwardRef.__repr__` if it is set. The module parameter carries semantic information about the forward ref. Show to the user that forward refs with same argument but different module are different. --- Lib/test/test_typing.py | 2 ++ Lib/typing.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 6e2a2b1978ab40..2bb5d61068a78c 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -2862,6 +2862,8 @@ def fun(x: a): def test_forward_repr(self): self.assertEqual(repr(List['int']), "typing.List[ForwardRef('int')]") + self.assertEqual(repr(List[ForwardRef('int', module='mod')]), + "typing.List[ForwardRef('int', module='mod')]") def test_union_forward(self): diff --git a/Lib/typing.py b/Lib/typing.py index 1de48cca00d84c..4a8bdf8132861e 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -779,7 +779,11 @@ def __ror__(self, other): return Union[other, self] def __repr__(self): - return f'ForwardRef({self.__forward_arg__!r})' + if self.__forward_module__ is None: + module_repr = '' + else: + module_repr = f', module={self.__forward_module__!r}' + return f'ForwardRef({self.__forward_arg__!r}{module_repr})' class _TypeVarLike: """Mixin for TypeVar-like types (TypeVar and ParamSpec).""" From a1cbd5fb5cd4ce1e71240abc575e3c6f75441a20 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 11 Feb 2022 20:01:50 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst diff --git a/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst b/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst new file mode 100644 index 00000000000000..35d00e516eca5a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst @@ -0,0 +1,3 @@ +The :meth:`__repr__` method of :class:`typing.ForwardRef` now +includes the ``module`` parameter of :class:`typing.ForwardRef` +when it is set. From 63b37eb700b77274bfaf3770f14e3c5463d1f87d Mon Sep 17 00:00:00 2001 From: Andreas Hangauer Date: Fri, 11 Feb 2022 21:57:01 +0100 Subject: [PATCH 3/3] remove trailing whitespace --- .../next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst b/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst index 35d00e516eca5a..669217e25f789d 100644 --- a/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst +++ b/Misc/NEWS.d/next/Library/2022-02-11-20-01-49.bpo-46333.PMTBY9.rst @@ -1,3 +1,3 @@ -The :meth:`__repr__` method of :class:`typing.ForwardRef` now -includes the ``module`` parameter of :class:`typing.ForwardRef` +The :meth:`__repr__` method of :class:`typing.ForwardRef` now +includes the ``module`` parameter of :class:`typing.ForwardRef` when it is set. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy