|
8 | 8 | import itertools |
9 | 9 | import pickle |
10 | 10 | from string.templatelib import Template, Interpolation |
| 11 | +import types |
11 | 12 | import typing |
12 | 13 | import sys |
13 | 14 | import unittest |
@@ -1864,26 +1865,39 @@ def foo(a: c1_gth, b: c2_gth): |
1864 | 1865 |
|
1865 | 1866 | def test_forward_equality_and_hash_with_cells(self): |
1866 | 1867 | """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.""" |
1871 | 1871 |
|
1872 | 1872 | 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"] |
1874 | 1875 |
|
1875 | | - def two(self) -> C[T]: # two cells: C, T |
1876 | | - pass |
| 1876 | + def two(_) -> C1 | C2: |
| 1877 | + """Two cells.""" |
1877 | 1878 |
|
1878 | 1879 | two_f_ga1 = get_annotations(two, format=Format.FORWARDREF)["return"] |
1879 | 1880 | two_f_ga2 = get_annotations(two, format=Format.FORWARDREF)["return"] |
1880 | 1881 |
|
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) |
1883 | 1898 |
|
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)) |
1887 | 1901 |
|
1888 | 1902 | def test_forward_equality_namespace(self): |
1889 | 1903 | def namespace1(): |
|
0 commit comments