File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1862,6 +1862,29 @@ 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+ """Regression test for GH-143831."""
1867+
1868+ class C [T ]:
1869+ def one (self ) -> C : # one cell: C
1870+ pass
1871+
1872+ one_f = ForwardRef ("C" , owner = one )
1873+ one_f_ga = get_annotations (one , format = Format .FORWARDREF )["return" ]
1874+
1875+ def two (self ) -> C [T ]: # two cells: C, T
1876+ pass
1877+
1878+ two_f_ga1 = get_annotations (two , format = Format .FORWARDREF )["return" ]
1879+ two_f_ga2 = get_annotations (two , format = Format .FORWARDREF )["return" ]
1880+
1881+ self .assertNotEqual (C .one_f , C .one_f_ga )
1882+ self .assertNotEqual (hash (C .one_f ), hash (C .one_f_ga ))
1883+
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 ))
1887+
18651888 def test_forward_equality_namespace (self ):
18661889 def namespace1 ():
18671890 a = ForwardRef ("A" )
You can’t perform that action at this time.
0 commit comments