File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ def __reduce__(self):
106106 )
107107
108108
109- def _reconstruct_pyfrozenlist (items , frozen ) :
109+ def _reconstruct_pyfrozenlist (items : list [ Any ] , frozen : bool ) -> "PyFrozenList" :
110110 """Helper function to reconstruct the pure Python FrozenList during unpickling.
111111 This function is needed since otherwise the class renaming confuses pickle."""
112112 fl = PyFrozenList (items )
Original file line number Diff line number Diff line change @@ -274,6 +274,20 @@ def test_deepcopy_frozen(self) -> None:
274274 with pytest .raises (RuntimeError ):
275275 copied .append (4 )
276276
277+ def test_deepcopy_frozen_circular (self ) -> None :
278+ orig = self .FrozenList ([1 , 2 ])
279+ orig .append (orig ) # Create circular reference
280+ orig .freeze ()
281+ copied = deepcopy (orig )
282+ assert copied [0 ] == 1
283+ assert copied [1 ] == 2
284+ assert len (copied [2 ]) == 3
285+ assert copied [2 ][0 ] == 1
286+ assert copied [2 ][1 ] == 2
287+ assert len (copied [2 ][2 ]) == 3
288+ # ... and so on. Testing equality when a structure includes itself is tough.
289+ assert orig .frozen
290+
277291 def test_deepcopy_nested (self ) -> None :
278292 inner = self .FrozenList ([1 , 2 ])
279293 orig = self .FrozenList ([inner , 3 ])
You can’t perform that action at this time.
0 commit comments