code: def class_instance_as_index(node):
      
      context = contextmod.InferenceContext()
      context.callcontext = contextmod.CallContext(args=[node])
  
      try:
          for inferred in node.igetattr("__index__", context=context):
              if not isinstance(inferred, bases.BoundMethod):
                  continue
  
              for result in inferred.infer_call_result(node, context=context):
                  if isinstance(result, nodes.Const) and isinstance(result.value, int):
                      return result
      except exceptions.InferenceError:
          pass
      return None
docs: Get the value as an index for the given instance.
  
      If an instance provides an __index__ method, then it can
      be used in some scenarios where an integer is expected,
      for instance when multiplying or subscripting a list.