libcst 1.8.6

A Python parser and Concrete Syntax Tree library.
Documentation
// Copyright (c) Meta Platforms, Inc. and affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree

use crate::nodes::traits::py::TryIntoPy;
use pyo3::prelude::*;

#[pymodule(gil_used = false)]
#[pyo3(name = "native")]
pub fn libcst_native(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
    #[pyfn(m)]
    #[pyo3(signature = (source, encoding=None))]
    fn parse_module(source: String, encoding: Option<&str>) -> PyResult<Py<PyAny>> {
        let m = crate::parse_module(source.as_str(), encoding)?;
        Python::attach(|py| m.try_into_py(py))
    }

    #[pyfn(m)]
    fn parse_expression(source: String) -> PyResult<Py<PyAny>> {
        let expr = crate::parse_expression(source.as_str())?;
        Python::attach(|py| expr.try_into_py(py))
    }

    #[pyfn(m)]
    fn parse_statement(source: String) -> PyResult<Py<PyAny>> {
        let stm = crate::parse_statement(source.as_str())?;
        Python::attach(|py| stm.try_into_py(py))
    }

    Ok(())
}