parameters: (node_or_string)
return_statement: return _convert(node_or_string)
docstring: Safely evaluate an expression node or a string containing a Python
      expression.  The string or node provided may only consist of the following
      Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
      sets, booleans, and None.
docstring_summary: Safely evaluate an expression node or a string containing a Python
      expression.  The string or node provided may only consist of the following
      Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
      sets, booleans, and None.
docstring_tokens: Safely evaluate an expression node or a string containing a Python expression . The string or node provided may only consist of the following Python literal structures : strings bytes numbers tuples lists dicts sets booleans and None .
function: def literal_eval(node_or_string):
      """
      Safely evaluate an expression node or a string containing a Python
      expression.  The string or node provided may only consist of the following
      Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
      sets, booleans, and None.
      """
      if isinstance(node_or_string, str):
          node_or_string = parse(node_or_string, mode='eval')
      if isinstance(node_or_string, Expression):
          node_or_string = node_or_string.body
      def _convert_num(node):
          if isinstance(node, Constant):
              if isinstance(node.value, (int, float, complex)):
                  return node.value
          elif isinstance(node, Num):
              return node.n
          raise ValueError('malformed node or string: ' + repr(node))
      def _convert_signed_num(node):
          if isinstance(node, UnaryOp) and isinstance(node.op, (UAdd, USub)):
              operand = _convert_num(node.operand)
              if isinstance(node.op, UAdd):
                  return + operand
              else:
                  return - operand
          return _convert_num(node)
      def _convert(node):
          if isinstance(node, Constant):
              return node.value
          elif isinstance(node, (Str, Bytes)):
              return node.s
          elif isinstance(node, Num):
              return node.n
          elif isinstance(node, Tuple):
              return tuple(map(_convert, node.elts))
          elif isinstance(node, List):
              return list(map(_convert, node.elts))
          elif isinstance(node, Set):
              return set(map(_convert, node.elts))
          elif isinstance(node, Dict):
              return dict(zip(map(_convert, node.keys),
                              map(_convert, node.values)))
          elif isinstance(node, NameConstant):
              return node.value
          elif isinstance(node, BinOp) and isinstance(node.op, (Add, Sub)):
              left = _convert_signed_num(node.left)
              right = _convert_num(node.right)
              if isinstance(left, (int, float)) and isinstance(right, complex):
                  if isinstance(node.op, Add):
                      return left + right
                  else:
                      return left - right
          return _convert_signed_num(node)
      return _convert(node_or_string)
function_tokens: def literal_eval ( node_or_string ) : if isinstance ( node_or_string , str ) : node_or_string = parse ( node_or_string , mode = 'eval' ) if isinstance ( node_or_string , Expression ) : node_or_string = node_or_string . body def _convert_num ( node ) : if isinstance ( node , Constant ) : if isinstance ( node . value , ( int , float , complex ) ) : return node . value elif isinstance ( node , Num ) : return node . n raise ValueError ( 'malformed node or string: ' + repr ( node ) ) def _convert_signed_num ( node ) : if isinstance ( node , UnaryOp ) and isinstance ( node . op , ( UAdd , USub ) ) : operand = _convert_num ( node . operand ) if isinstance ( node . op , UAdd ) : return + operand else : return - operand return _convert_num ( node ) def _convert ( node ) : if isinstance ( node , Constant ) : return node . value elif isinstance ( node , ( Str , Bytes ) ) : return node . s elif isinstance ( node , Num ) : return node . n elif isinstance ( node , Tuple ) : return tuple ( map ( _convert , node . elts ) ) elif isinstance ( node , List ) : return list ( map ( _convert , node . elts ) ) elif isinstance ( node , Set ) : return set ( map ( _convert , node . elts ) ) elif isinstance ( node , Dict ) : return dict ( zip ( map ( _convert , node . keys ) , map ( _convert , node . values ) ) ) elif isinstance ( node , NameConstant ) : return node . value elif isinstance ( node , BinOp ) and isinstance ( node . op , ( Add , Sub ) ) : left = _convert_signed_num ( node . left ) right = _convert_num ( node . right ) if isinstance ( left , ( int , float ) ) and isinstance ( right , complex ) : if isinstance ( node . op , Add ) : return left + right else : return left - right return _convert_signed_num ( node ) return _convert ( node_or_string )