summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authoraha79 <34090357+aha79@users.noreply.github.com>2022-02-12 15:35:57 (GMT)
committerGitHub <noreply@github.com>2022-02-12 15:35:57 (GMT)
commitb70690bb37cc4bac695051484734eede0c1f9ada (patch)
tree3ebf94f7f4ee7a00260db3b9e40b92c748303bfa /Lib/typing.py
parent8aaaf7e182e22026c3487a3b86d4d7d4f0f5f778 (diff)
downloadcpython-b70690bb37cc4bac695051484734eede0c1f9ada.zip
cpython-b70690bb37cc4bac695051484734eede0c1f9ada.tar.gz
cpython-b70690bb37cc4bac695051484734eede0c1f9ada.tar.bz2
bpo-46333: include `module` in `ForwardRef.__repr__` (#31283)
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. Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 1de48cc..4a8bdf8 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -779,7 +779,11 @@ class ForwardRef(_Final, _root=True):
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)."""