mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-45489: Update ForwardRef to support | operator. (GH-28991)
This commit is contained in:
parent
4ecd119b00
commit
15ad52fbf6
3 changed files with 14 additions and 0 deletions
|
@ -2903,6 +2903,12 @@ class ForwardRefTests(BaseTestCase):
|
|||
self.assertNotEqual(gth(Loop, globals())['attr'], Final[int])
|
||||
self.assertNotEqual(gth(Loop, globals())['attr'], Final)
|
||||
|
||||
def test_or(self):
|
||||
X = ForwardRef('X')
|
||||
# __or__/__ror__ itself
|
||||
self.assertEqual(X | "x", Union[X, "x"])
|
||||
self.assertEqual("x" | X, Union["x", X])
|
||||
|
||||
|
||||
class OverloadTests(BaseTestCase):
|
||||
|
||||
|
|
|
@ -719,6 +719,12 @@ class ForwardRef(_Final, _root=True):
|
|||
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})'
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Update :class:`~typing.ForwardRef` to support ``|`` operator. Patch by
|
||||
Dong-hee Na.
|
Loading…
Add table
Add a link
Reference in a new issue