code: def check_against_PyObject_RichCompareBool(self, L):
      ## The idea here is to exploit the fact that unsafe_tuple_compare uses
      ## PyObject_RichCompareBool for the second elements of tuples. So we have,
      ## for (most) L, sorted(L) == [y[1] for y in sorted([(0,x) for x in L])]
      ## This will work as long as __eq__ => not __lt__ for all the objects in L,
      ## which holds for all the types used below.
      ##
      ## Testing this way ensures that the optimized implementation remains consistent
      ## with the naive implementation, even if changes are made to any of the
      ## richcompares.
      ##
      ## This function tests sorting for three lists (it randomly shuffles each one):
      ##                        1. L
      ##                        2. [(x,) for x in L]
      ##                        3. [((x,),) for x in L]
  
      random.seed(0)
      random.shuffle(L)
      L_1 = L[:]
      L_2 = [(x,) for x in L]
      L_3 = [((x,),) for x in L]
      for L in [L_1, L_2, L_3]:
          optimized = sorted(L)
          reference = [y[1] for y in sorted([(0, x) for x in L])]
          for opt, ref in zip(optimized, reference):
              self.assertIs(opt, ref)
  
imports: from test import support
  import random
  import unittest
  from functools import cmp_to_key
label_desc: Use image node_id 2 for calling a global function with example usage: check_against_PyObject_RichCompareBool(L) without return types