Skip to content

Commit d8f5bc8

Browse files
committed
Test two paths
1 parent 6c36442 commit d8f5bc8

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

Lib/test/test_annotationlib.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import itertools
99
import pickle
1010
from string.templatelib import Template, Interpolation
11+
import types
1112
import typing
1213
import sys
1314
import unittest
@@ -1864,26 +1865,39 @@ def foo(a: c1_gth, b: c2_gth):
18641865

18651866
def test_forward_equality_and_hash_with_cells(self):
18661867
"""Regression test for GH-143831."""
1867-
1868-
class C[T]:
1869-
def one(self) -> C: # one cell: C
1870-
pass
1868+
class A:
1869+
def one(_) -> C1:
1870+
"""One cell."""
18711871

18721872
one_f = ForwardRef("C", owner=one)
1873-
one_f_ga = get_annotations(one, format=Format.FORWARDREF)["return"]
1873+
one_f_ga1 = get_annotations(one, format=Format.FORWARDREF)["return"]
1874+
one_f_ga2 = get_annotations(one, format=Format.FORWARDREF)["return"]
18741875

1875-
def two(self) -> C[T]: # two cells: C, T
1876-
pass
1876+
def two(_) -> C1 | C2:
1877+
"""Two cells."""
18771878

18781879
two_f_ga1 = get_annotations(two, format=Format.FORWARDREF)["return"]
18791880
two_f_ga2 = get_annotations(two, format=Format.FORWARDREF)["return"]
18801881

1881-
self.assertNotEqual(C.one_f, C.one_f_ga)
1882-
self.assertNotEqual(hash(C.one_f), hash(C.one_f_ga))
1882+
type C1 = None
1883+
type C2 = None
1884+
1885+
self.assertNotEqual(A.one_f, A.one_f_ga1)
1886+
self.assertNotEqual(hash(A.one_f), hash(A.one_f_ga1))
1887+
1888+
self.assertIs(A.one_f_ga1.__cell__, A.one_f_ga1.__cell__)
1889+
self.assertIsInstance(A.one_f_ga1.__cell__, types.CellType)
1890+
self.assertIsInstance(A.one_f_ga1.__cell__, types.CellType)
1891+
1892+
self.assertEqual(A.one_f_ga1, A.one_f_ga2)
1893+
self.assertEqual(hash(A.one_f_ga1), hash(A.one_f_ga2))
1894+
1895+
self.assertIsNot(A.two_f_ga1.__cell__, A.two_f_ga2.__cell__)
1896+
self.assertIsInstance(A.two_f_ga1.__cell__, dict)
1897+
self.assertIsInstance(A.two_f_ga1.__cell__, dict)
18831898

1884-
self.assertIsNot(C.two_f_ga1, C.two_f_ga2) # self-test
1885-
self.assertEqual(C.two_f_ga1, C.two_f_ga2) # same cell
1886-
self.assertEqual(hash(C.two_f_ga1), hash(C.two_f_ga2))
1899+
self.assertEqual(A.two_f_ga1, A.two_f_ga2)
1900+
self.assertEqual(hash(A.two_f_ga1), hash(A.two_f_ga2))
18871901

18881902
def test_forward_equality_namespace(self):
18891903
def namespace1():

0 commit comments

Comments
 (0)