Skip to content

Commit 5b0e92d

Browse files
committedMay 3, 2023
Refactor common::str::repr using common::escape
1 parent ae9d3c3 commit 5b0e92d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎ast/src/constant.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ impl std::fmt::Display for Constant {
4141
match self {
4242
Constant::None => f.pad("None"),
4343
Constant::Bool(b) => f.pad(if *b { "True" } else { "False" }),
44-
Constant::Str(s) => rustpython_common::str::repr(s).fmt(f),
44+
Constant::Str(s) => {
45+
use rustpython_common::escape::Escape;
46+
rustpython_common::escape::UnicodeEscape::new_repr(s.as_str()).write_quoted(f)
47+
}
4548
Constant::Bytes(b) => {
4649
f.pad(&rustpython_common::bytes::repr(b).map_err(|_err| std::fmt::Error)?)
4750
}

‎ast/src/unparse.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,10 @@ impl<'a> Unparser<'a> {
509509
if is_spec {
510510
self.unparse_fstring_body(values, is_spec)
511511
} else {
512+
use rustpython_common::escape::Escape;
512513
self.p("f")?;
513514
let body = to_string_fmt(|f| Unparser::new(f).unparse_fstring_body(values, is_spec));
514-
fmt::Display::fmt(&rustpython_common::str::repr(&body), &mut self.f)
515+
rustpython_common::escape::UnicodeEscape::new_repr(&body).write_quoted(&mut self.f)
515516
}
516517
}
517518
}

0 commit comments

Comments
 (0)
Please sign in to comment.