def object_len(node, context=None):
from astroid.objects import FrozenSet<EOL>inferred_node = safe_infer(node, context=context)<EOL>if inferred_node is None or inferred_node is util.Uninferable:<EOL><INDENT>raise exceptions.InferenceError(node=node)<EOL><DEDENT>if isinstance(inferred_node, nodes.Const) and isinstance(<EOL>inferred_node.value, (bytes, str)<EOL>):<EOL><INDENT>return len(inferred_node.value)<EOL><DEDENT>if isinstance(inferred_node, (nodes.List, nodes.Set, nodes.Tuple, FrozenSet)):<EOL><INDENT>return len(inferred_node.elts)<EOL><DEDENT>if isinstance(inferred_node, nodes.Dict):<EOL><INDENT>return len(inferred_node.items)<EOL><DEDENT>try:<EOL><INDENT>node_type = object_type(inferred_node, context=context)<EOL>len_call = next(node_type.igetattr("<STR_LIT>", context=context))<EOL><DEDENT>except exceptions.AttributeInferenceError:<EOL><INDENT>raise exceptions.AstroidTypeError(<EOL>"<STR_LIT>".format(len_call.pytype())<EOL>)<EOL><DEDENT>result_of_len = next(len_call.infer_call_result(node, context))<EOL>if (<EOL>isinstance(result_of_len, nodes.Const)<EOL>and result_of_len.pytype() == "<STR_LIT>"<EOL>):<EOL><INDENT>return result_of_len.value<EOL><DEDENT>raise exceptions.AstroidTypeError(<EOL>"<STR_LIT>".format(result_of_len)<EOL>)<EOL>
Infer length of given node object

    :param Union[nodes.ClassDef, nodes.Instance] node:
    :param node: Node to infer length of

    :raises AstroidTypeError: If an invalid node is returned
        from __len__ method or no __len__ method exists
    :raises InferenceError: If the given node cannot be inferred
        or if multiple nodes are inferred
    :rtype int: Integer length of node