@@ -2772,67 +2772,20 @@ def __eq__(self, o):
27722772 g .assert_not_called ()
27732773
27742774 # Test removing root[1] (of type R) from [U(), R()].
2775- #
2776- # In pure Python, using root.clear() sets the children
2777- # list to [] without calling list.clear().
2778- #
2779- # For this reason, the call to root.remove() first
2780- # checks root[0] and sets the children list to []
2781- # since either root[0] or root[1] is an evil element.
2782- #
2783- # Since checking root[1] still uses the old reference
2784- # to the children list, PyObject_RichCompareBool() branches
2785- # to the fast Py_EQ path and Y.__eq__() is called exactly
2786- # once (when checking root[0]).
2787- #
2788- # NOTE(picnixz): the Python and C implementations
2789- # could be aligned if 'self._children = []' is
2790- # replaced by 'self._children.clear()'; however,
2791- # this should be carefully addressed since any
2792- # reference to 'self._children' will be affected.
27932775 is_special = is_python_implementation () and raises and Z is Y
2794- if is_special :
2795- def check (f , never , arg0spec , arg1spec ):
2796- never .assert_not_called ()
2797- f .assert_called_once ()
2798-
2799- arg0cls , arg0tag = arg0spec
2800- self .assertIs (f .call_args [0 ][0 ].__class__ , arg0cls )
2801- self .assertIs (f .call_args [0 ][0 ].tag , arg0tag )
2802-
2803- arg1cls , arg1tag = arg1spec
2804- self .assertIs (f .call_args [0 ][1 ].__class__ , arg1cls )
2805- self .assertIs (f .call_args [0 ][1 ].tag , arg1tag )
2806-
2807- with self .subTest ("remove root[1] from [E(), Z()]" ):
2808- root = E ('top' )
2809- root .extend ([E ('one' ), Z ('rem' )])
2810- with equal_wrapper (E ) as never , equal_wrapper (Z ) as f :
2811- root .remove (root [1 ])
2812- # Calling PyObject_RichCompareBool(root[0], root[1], Py_EQ)
2813- # delegates to Z.__eq__(root[1], root[0]) since E.__eq__ is
2814- # not implemented. In particular, E.__eq__ is never called
2815- # but Z.__eq__ is called when checking root[0].
2816- check (f , never , (Z , 'rem' ), (E , 'one' ))
2817-
2818- with self .subTest ("remove root[1] from [Z(), E()]" ):
2819- root = E ('top' )
2820- root .extend ([Z ('one' ), E ('rem' )])
2821- with equal_wrapper (E ) as never , equal_wrapper (Z ) as f :
2822- root .remove (root [1 ])
2823- # Calling PyObject_RichCompareBool(root[0], root[1], Py_EQ)
2824- # delegates to Z.__eq__(root[0], root[1]). In particular,
2825- # E.__eq__ is never called due to the Py_EQ fast path.
2826- check (f , never , (Z , 'one' ), (E , 'rem' ))
2827-
2828- with self .subTest ("remove root[1] from [Z(), Z()]" ):
2829- root = E ('top' )
2830- root .extend ([Z ('one' ), Z ('rem' )])
2831- self .assertNotEqual (list (root ), [])
2832- with equal_wrapper (E ) as never , equal_wrapper (Z ) as f :
2833- root .remove (root [1 ])
2834- # Same arguments as for the [Z(), E()] case.
2835- check (f , never , (Z , 'one' ), (Z , 'rem' ))
2776+ if is_python_implementation () and raises and Z is Y :
2777+ # In pure Python, using root.clear() sets the children
2778+ # list to [] without calling list.clear().
2779+ #
2780+ # For this reason, the call to root.remove() first
2781+ # checks root[0] and sets the children list to []
2782+ # since either root[0] or root[1] is an evil element.
2783+ #
2784+ # Since checking root[1] still uses the old reference
2785+ # to the children list, PyObject_RichCompareBool() branches
2786+ # to the fast Py_EQ path and Y.__eq__() is called exactly
2787+ # once (when checking root[0]).
2788+ continue
28362789 else :
28372790 cases = self .cases_for_remove_existing_with_mutations (E , Z )
28382791 for R , U , description in cases :
0 commit comments