def class_instance_as_index(node):
context = contextmod.InferenceContext()<EOL>context.callcontext = contextmod.CallContext(args=[node])<EOL>try:<EOL><INDENT>for inferred in node.igetattr("<STR_LIT>", context=context):<EOL><INDENT>if not isinstance(inferred, bases.BoundMethod):<EOL><INDENT>continue<EOL><DEDENT>for result in inferred.infer_call_result(node, context=context):<EOL><INDENT>if isinstance(result, nodes.Const) and isinstance(result.value, int):<EOL><INDENT>return result<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except exceptions.InferenceError:<EOL><INDENT>pass<EOL><DEDENT>return None<EOL>
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.