Skip to content

Commit 973643e

Browse files
committed
Add base test
1 parent ff81d6a commit 973643e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lib/test/test_annotationlib.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,30 @@ def foo(a: c1_gth, b: c2_gth):
18621862
self.assertNotEqual(hash(c3), hash(c4))
18631863
self.assertEqual(hash(c3), hash(ForwardRef("int", module=__name__)))
18641864

1865+
def test_forward_equality_and_hash_with_cells(self):
1866+
"""See GH-143831."""
1867+
1868+
class C[T]:
1869+
def one(self) -> C: # one cell: C
1870+
pass
1871+
1872+
one_anns = get_annotations(one, format=Format.FORWARDREF)
1873+
one_f = ForwardRef("C", owner=one)
1874+
one_f_ga = one_anns["return"]
1875+
1876+
def two(self) -> C[T]: # two cells: C, T
1877+
pass
1878+
1879+
two_f_ga1 = get_annotations(two, format=Format.FORWARDREF)["return"]
1880+
two_f_ga2 = get_annotations(two, format=Format.FORWARDREF)["return"]
1881+
1882+
self.assertNotEqual(C.one_f, C.one_f_ga)
1883+
self.assertNotEqual(hash(C.one_f), hash(C.one_f_ga))
1884+
1885+
self.assertIsNot(C.two_f_ga1, C.two_f_ga2) # self-test
1886+
self.assertEqual(C.two_f_ga1, C.two_f_ga2) # same cell
1887+
self.assertEqual(hash(C.two_f_ga1), hash(C.two_f_ga2))
1888+
18651889
def test_forward_equality_namespace(self):
18661890
def namespace1():
18671891
a = ForwardRef("A")

0 commit comments

Comments
 (0)