code: def test_0d_object_subclass(self):
      # make sure that subclasses which return 0ds instead
      # of scalars don't cause infinite recursion in str
      class sub(np.ndarray):
          def __new__(cls, inp):
              obj = np.asarray(inp).view(cls)
              return obj
  
          def __getitem__(self, ind):
              ret = super().__getitem__(ind)
              return sub(ret)
  
      x = sub(1)
      assert_equal(repr(x), "sub(1)")
      assert_equal(str(x), "1")
  
      x = sub([1, 1])
      assert_equal(repr(x), "sub([1, 1])")
      assert_equal(str(x), "[1 1]")
  
      # check it works properly with object arrays too
      x = sub(None)
      assert_equal(repr(x), "sub(None, dtype=object)")
      assert_equal(str(x), "None")
  
      # plus recursive object arrays (even depth > 1)
      y = sub(None)
      x[()] = y
      y[()] = x
      assert_equal(
          repr(x),
          "sub(sub(sub(..., dtype=object), dtype=object), dtype=object)",
      )
      assert_equal(str(x), "...")
      x[()] = 0  # resolve circular references for garbage collector
  
      # nested 0d-subclass-object
      x = sub(None)
      x[()] = sub(None)
      assert_equal(
          repr(x), "sub(sub(None, dtype=object), dtype=object)"
      )
      assert_equal(str(x), "None")
  
      # gh-10663
      class DuckCounter(np.ndarray):
          def __getitem__(self, item):
              result = super().__getitem__(item)
              if not isinstance(result, DuckCounter):
                  result = result[...].view(DuckCounter)
              return result
  
          def to_string(self):
              return {0: "zero", 1: "one", 2: "two"}.get(
                  self.item(), "many"
              )
  
          def __str__(self):
              if self.shape == ():
                  return self.to_string()
              else:
                  fmt = {"all": lambda x: x.to_string()}
                  return np.array2string(self, formatter=fmt)
  
      dc = np.arange(5).view(DuckCounter)
      assert_equal(str(dc), "[zero one two many many]")
      assert_equal(str(dc[0]), "zero")
  
imports: import sys
  import gc
  from hypothesis import given
  from hypothesis.extra import numpy
  import pytest
  import numpy
  from numpy.testing import assert_, assert_equal, assert_raises, assert_warns, HAS_REFCOUNT, assert_raises_regex
  from numpy.core.arrayprint import _typelessdata
  import textwrap
label_desc: Use image node_id 4 for calling the TestArrayRepr obj's underlying member method code with example usage: obj.test_0d_object_subclass() and returns: obj, sub, result, dict, self, np