summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authoraha79 <34090357+aha79@users.noreply.github.com>2022-02-17 03:28:18 (GMT)
committerGitHub <noreply@github.com>2022-02-17 03:28:18 (GMT)
commit6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a (patch)
treeee86170817ab4a7f892d38001ee95fed9f300692 /Lib/test
parentde6043e596492201cc1a1eb28038970bb69f3107 (diff)
downloadcpython-6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a.zip
cpython-6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a.tar.gz
cpython-6e7b813195f9bd6a2a15c1f00ef2c0180f6c751a.tar.bz2
bpo-46333: Honor `module` parameter in ForwardRef (GH-30536)
The `module` parameter carries semantic information about the forward ref. Forward refs are different if they refer to different module even if they have the same name. This affects the `__eq__`, `__repr__` and `__hash__` methods. Co-authored-by: Andreas Hangauer <andreas.hangauer@siemens.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 9548a0c..1b3eb06 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -2800,6 +2800,10 @@ class ForwardRefTests(BaseTestCase):
fr = typing.ForwardRef('int')
self.assertEqual(fr, typing.ForwardRef('int'))
self.assertNotEqual(List['int'], List[int])
+ self.assertNotEqual(fr, typing.ForwardRef('int', module=__name__))
+ frm = typing.ForwardRef('int', module=__name__)
+ self.assertEqual(frm, typing.ForwardRef('int', module=__name__))
+ self.assertNotEqual(frm, typing.ForwardRef('int', module='__other_name__'))
def test_forward_equality_gth(self):
c1 = typing.ForwardRef('C')
@@ -2836,6 +2840,14 @@ class ForwardRefTests(BaseTestCase):
self.assertEqual(hash(c1_gth), hash(c2_gth))
self.assertEqual(hash(c1), hash(c1_gth))
+ c3 = typing.ForwardRef('int', module=__name__)
+ c4 = typing.ForwardRef('int', module='__other_name__')
+
+ self.assertNotEqual(hash(c3), hash(c1))
+ self.assertNotEqual(hash(c3), hash(c1_gth))
+ self.assertNotEqual(hash(c3), hash(c4))
+ self.assertEqual(hash(c3), hash(typing.ForwardRef('int', module=__name__)))
+
def test_forward_equality_namespace(self):
class A:
pass