[issue45489] ForwardRef does not support | operator

Dong-hee Na report at bugs.python.org
Sat Oct 16 09:43:34 EDT 2021


Dong-hee Na <donghee.na at python.org> added the comment:

--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -719,6 +719,12 @@ def __eq__(self, other):
     def __hash__(self):
         return hash(self.__forward_arg__)

+    def __or__(self, other):
+        return Union[self, other]
+
+    def __ror__(self, other):
+        return Union[other, self]
+
     def __repr__(self):
         return f'ForwardRef({self.__forward_arg__!r})'

This can be easily fixed, but I am waiting for guido and ken to check whether this is an intentioned operation.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45489>
_______________________________________


More information about the Python-bugs-list mailing list