def tuple_eval(source):
 node = ast.parse(source, '<source>', mode='eval')
 if (not isinstance(node.body, ast.Tuple)):
  raise ValueError(('%r is not a tuple literal' % source))
 if (not all(((isinstance(el, (ast.Str, ast.Num)) or (isinstance(el, ast.UnaryOp) and isinstance(el.op, (ast.UAdd, ast.USub)) and isinstance(el.operand, ast.Num))) for el in node.body.elts))):
  raise ValueError('Can only contain numbers or strings')
 return literal_eval(source)

def tuple_eval ( source ) : node = ast . parse ( source , '<source>' , mode = 'eval' ) if ( not isinstance ( node . body , ast . Tuple ) ) : raise ValueError ( ( '%r is not a tuple literal' % source ) ) if ( not all ( ( ( isinstance ( el , ( ast . Str , ast . Num ) ) or ( isinstance ( el , ast . UnaryOp ) and isinstance ( el . op , ( ast . UAdd , ast . USub ) ) and isinstance ( el . operand , ast . Num ) ) ) for el in node . body . elts ) ) ) : raise ValueError ( 'Can only contain numbers or strings' ) return literal_eval ( source )
evaluate a python tuple literal source where the elements are constrained to be int .