mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
repr as single quote default
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
use crate::str::{Quote, ReprOverflowError};
|
||||
|
||||
pub fn repr(b: &[u8], quote: Quote) -> Result<String, ReprOverflowError> {
|
||||
pub fn repr(b: &[u8]) -> Result<String, ReprOverflowError> {
|
||||
repr_with(b, &[], "", Quote::Single)
|
||||
}
|
||||
|
||||
pub fn repr_with_quote(b: &[u8], quote: Quote) -> Result<String, ReprOverflowError> {
|
||||
repr_with(b, &[], "", quote)
|
||||
}
|
||||
|
||||
|
||||
@@ -350,12 +350,8 @@ macro_rules! ascii {
|
||||
|
||||
/// Get a Display-able type that formats to the python `repr()` of the string value
|
||||
#[inline]
|
||||
pub fn repr(s: &str, quote: Quote) -> Repr<'_> {
|
||||
Repr {
|
||||
s,
|
||||
quote,
|
||||
info: OnceCell::new(),
|
||||
}
|
||||
pub fn repr(s: &str) -> Repr<'_> {
|
||||
Repr::new(s, Quote::Single)
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@@ -423,10 +419,19 @@ pub struct Repr<'a> {
|
||||
s: &'a str,
|
||||
// the quote type we prefer to use
|
||||
quote: Quote,
|
||||
// the tuple is dquouted, out_len
|
||||
info: OnceCell<Result<ReprInfo, ReprOverflowError>>,
|
||||
}
|
||||
|
||||
impl<'a> Repr<'a> {
|
||||
pub fn new(s: &'a str, quote: Quote) -> Self {
|
||||
Self {
|
||||
s,
|
||||
quote,
|
||||
info: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr<'_> {
|
||||
fn get_info(&self) -> Result<ReprInfo, ReprOverflowError> {
|
||||
*self.info.get_or_init(|| ReprInfo::get(self.s, self.quote))
|
||||
|
||||
@@ -249,7 +249,12 @@ impl PyBytesInner {
|
||||
|
||||
pub fn repr(&self, class_name: Option<&str>, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let repr = if let Some(class_name) = class_name {
|
||||
rustpython_common::bytes::repr_with(&self.elements, &[class_name, "("], ")")
|
||||
rustpython_common::bytes::repr_with(
|
||||
&self.elements,
|
||||
&[class_name, "("],
|
||||
")",
|
||||
rustpython_common::str::Quote::Single,
|
||||
)
|
||||
} else {
|
||||
rustpython_common::bytes::repr(&self.elements)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user