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>
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):
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)."""
--- /dev/null
+The :meth:`__repr__` method of :class:`typing.ForwardRef` now\r
+includes the ``module`` parameter of :class:`typing.ForwardRef`\r
+when it is set.