def src2ast ( src : str ) -> Expression : try : return ast . parse ( src , mode = 'eval' ) except SyntaxError : raise ValueError ( "Not a valid expression." ) from None
how to add ast in python
Return ast . Expression created from source code given in src .
def src2ast(src: str) -> Expression:
    """Return ast.Expression created from source code given in `src`."""
    try:
        return ast.parse(src, mode='eval')
    except SyntaxError:
        raise ValueError("Not a valid expression.") from None