Function parse

Source
pub fn parse(
    input: impl AsRef<str>,
    filename: impl AsRef<str>,
) -> PyResult<Module>
Expand description

Parses Python code and returns the AST as a Module (backward compatible version).

This is the original parse function that returns PyResult for backward compatibility. For better error messages with location information, use parse_enhanced instead.

§Arguments

  • input - The Python source code to parse
  • filename - The filename to associate with the parsed code

§Returns

  • PyResult<Module> - The parsed AST module or a PyO3 error

§Examples

use python_ast::parse;
 
let code = "x = 1 + 2";
let module = parse(code, "example.py").unwrap();