Upgrade RustPython (#4747)

This commit is contained in:
Micha Reiser 2023-05-31 10:26:35 +02:00 committed by GitHub
parent 06bcb85f81
commit 6c1ff6a85f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 104 additions and 93 deletions

View file

@ -1456,7 +1456,8 @@ impl<'a> Generator<'a> {
#[cfg(test)]
mod tests {
use rustpython_parser as parser;
use rustpython_ast::Suite;
use rustpython_parser::Parse;
use crate::newlines::LineEnding;
use crate::source_code::stylist::{Indentation, Quote};
@ -1466,7 +1467,7 @@ mod tests {
let indentation = Indentation::default();
let quote = Quote::default();
let line_ending = LineEnding::default();
let program = parser::parse_program(contents, "<filename>").unwrap();
let program = Suite::parse(contents, "<filename>").unwrap();
let stmt = program.first().unwrap();
let mut generator = Generator::new(&indentation, quote, line_ending);
generator.unparse_stmt(stmt);
@ -1479,7 +1480,7 @@ mod tests {
line_ending: LineEnding,
contents: &str,
) -> String {
let program = parser::parse_program(contents, "<filename>").unwrap();
let program = Suite::parse(contents, "<filename>").unwrap();
let stmt = program.first().unwrap();
let mut generator = Generator::new(indentation, quote, line_ending);
generator.unparse_stmt(stmt);

View file

@ -3,8 +3,7 @@ use std::fmt::{Debug, Formatter};
use std::sync::Arc;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser as parser;
use rustpython_parser::{lexer, Mode, ParseError};
use rustpython_parser::{ast, lexer, Mode, Parse, ParseError};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -26,7 +25,7 @@ mod stylist;
/// Run round-trip source code generation on a given Python code.
pub fn round_trip(code: &str, source_path: &str) -> Result<String, ParseError> {
let locator = Locator::new(code);
let python_ast = parser::parse_program(code, source_path)?;
let python_ast = ast::Suite::parse(code, source_path)?;
let tokens: Vec<_> = lexer::lex(code, Mode::Module).collect();
let stylist = Stylist::from_tokens(&tokens, &locator);
let mut generator: Generator = (&stylist).into();