code: def test_class_sorting(self):
      class Foo:  # noqa: B903
          def __init__(self, x: int) -> None:
              self.x = x
  
          def __lt__(self, other) -> bool:
              # type: (Foo) -> bool
              return self.x < other.x
  
          def getVal(self):
              return self.x
  
      make_global(Foo)  # see [local resolution in python]
  
      def test(
          li: List[Foo], reverse: bool = False
      ) -> Tuple[List[int], List[int]]:
          li_sorted = sorted(li)
          ret_sorted = torch.jit.annotate(List[int], [])
          for foo in li_sorted:
              ret_sorted.append(foo.getVal())
  
          li.sort(reverse=reverse)
          ret_sort = torch.jit.annotate(List[int], [])
          for foo in li:
              ret_sort.append(foo.getVal())
          return ret_sorted, ret_sort
  
      self.checkScript(test, ([Foo(2), Foo(1), Foo(3)],))
      self.checkScript(test, ([Foo(2), Foo(1), Foo(3)], True))
      self.checkScript(test, ([Foo(2)],))
      self.checkScript(test, ([],))
  
      @torch.jit.script
      def test_list_no_reverse():
          li = [Foo(3), Foo(1)]
          li.sort()
          return li[0].getVal()
  
      self.assertEqual(test_list_no_reverse(), 1)
  
      @torch.jit.script
      def test_sorted_copies():
          li = [Foo(3), Foo(1)]
          li_sorted = sorted(li)
          return li[0].getVal(), li_sorted[0].getVal()
  
      self.assertEqual(test_sorted_copies(), (3, 1))
  
      @torch.jit.script
      def test_nested_inside_tuple():
          li = [(1, Foo(12)), (1, Foo(11))]
          li.sort()
          return [
              (li[0][0], li[0][1].getVal()),
              (li[1][0], li[1][1].getVal()),
          ]
  
      self.assertEqual(test_nested_inside_tuple(), [(1, 11), (1, 12)])
  
      with self.assertRaisesRegexWithHighlight(
          RuntimeError, "bool' for argument 'reverse", ""
      ):
  
          @torch.jit.script
          def test():
              li = [Foo(1)]
              li.sort(li)
              return li
  
          test()
  
      with self.assertRaisesRegexWithHighlight(
          RuntimeError, "must define a __lt__", ""
      ):
  
          @torch.jit.script
          class NoMethod:
              def __init__(self):
                  pass
  
          @torch.jit.script
          def test():
              li = [NoMethod(), NoMethod()]
              li.sort()
              return li
  
          test()
  
      @torch.jit.script
      class WrongLt:
          def __init__(self):
              pass
  
          # lt method defined with the wrong signature
          def __lt__(self, other):
              pass
  
      with self.assertRaisesRegexWithHighlight(
          RuntimeError, "must define a __lt__", ""
      ):
  
          @torch.jit.script
          def test():
              li = [WrongLt(), WrongLt()]
              li.sort()
              return li
  
          test()
  
imports: import io
  import os
  import sys
  import unittest
  import torch
  import torch.nn
  from torch.testing import FileCheck
  from typing import Any
  from torch.testing._internal.jit_utils import JitTestCase, make_global
  import torch.testing._internal.jit_utils
  from torch.testing._internal.common_utils import IS_SANDCASTLE, skipIfTorchDynamo
  from typing import List, Tuple, Iterable, Optional, Dict
label_desc: Use image node_id 19 for calling the TestClassType obj's underlying member method code with example usage: obj.test_class_sorting() and returns: ret_sorted,  ret_sort, li, li,  li_sorted, list, unknown, self, li, li, li