import builtins
import re


def safer_eval(statement, locals):
    """A safer eval function. Does not allow __ or try statements, only includes certain 'safe' builtins."""
    allowed_builtins = ['True', 'False', 'str', 'bytes', 'int', 'float', 'len', 'any', 'all', 'sorted']
    for name in allowed_builtins:
        locals[name] = getattr(builtins, name)
    if re.search(r'__|try\s*:|lambda', statement):
        raise ValueError('`__`, lambda or try blocks not allowed in if statements.')
    return eval(statement, {'__builtins__': None}, locals)