diff --git a/ast/src/constant.rs b/ast/src/constant.rs index 7b40fb1..d81d7fb 100644 --- a/ast/src/constant.rs +++ b/ast/src/constant.rs @@ -41,12 +41,13 @@ impl std::fmt::Display for Constant { match self { Constant::None => f.pad("None"), Constant::Bool(b) => f.pad(if *b { "True" } else { "False" }), - Constant::Str(s) => { - use rustpython_common::escape::Escape; - rustpython_common::escape::UnicodeEscape::new_repr(s.as_str()).write_quoted(f) - } + Constant::Str(s) => rustpython_common::escape::UnicodeEscape::new_repr(s.as_str()) + .str_repr() + .write(f), Constant::Bytes(b) => { - f.pad(&rustpython_common::bytes::repr(b).map_err(|_err| std::fmt::Error)?) + let escape = rustpython_common::escape::AsciiEscape::new_repr(b); + let repr = escape.bytes_repr().to_string().unwrap(); + f.pad(&repr) } Constant::Int(i) => i.fmt(f), Constant::Tuple(tup) => { diff --git a/ast/src/unparse.rs b/ast/src/unparse.rs index 1af7bf2..e7e1bce 100644 --- a/ast/src/unparse.rs +++ b/ast/src/unparse.rs @@ -509,10 +509,11 @@ impl<'a> Unparser<'a> { if is_spec { self.unparse_fstring_body(values, is_spec) } else { - use rustpython_common::escape::Escape; self.p("f")?; let body = to_string_fmt(|f| Unparser::new(f).unparse_fstring_body(values, is_spec)); - rustpython_common::escape::UnicodeEscape::new_repr(&body).write_quoted(&mut self.f) + rustpython_common::escape::UnicodeEscape::new_repr(&body) + .str_repr() + .write(&mut self.f) } } }