Skip to main content

parse_enhanced

Function parse_enhanced 

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

Parses Python code and returns the AST as a Module with improved error handling.

This function accepts any type that can be converted to a string reference, making it flexible for different input types. It provides detailed error information including file location and helpful guidance when parsing fails.

§Arguments

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

§Returns

  • CrateResult<Module> - The parsed AST module or a detailed error with location info

§Examples

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