Skip to content

Commit 9cc8f2d

Browse files
committed
repr as single quote default
1 parent 2315ce9 commit 9cc8f2d

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

common/src/bytes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use crate::str::{Quote, ReprOverflowError};
22

3-
pub fn repr(b: &[u8], quote: Quote) -> Result<String, ReprOverflowError> {
3+
pub fn repr(b: &[u8]) -> Result<String, ReprOverflowError> {
4+
repr_with(b, &[], "", Quote::Single)
5+
}
6+
7+
pub fn repr_with_quote(b: &[u8], quote: Quote) -> Result<String, ReprOverflowError> {
48
repr_with(b, &[], "", quote)
59
}
610

common/src/str.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,8 @@ macro_rules! ascii {
350350

351351
/// Get a Display-able type that formats to the python `repr()` of the string value
352352
#[inline]
353-
pub fn repr(s: &str, quote: Quote) -> Repr<'_> {
354-
Repr {
355-
s,
356-
quote,
357-
info: OnceCell::new(),
358-
}
353+
pub fn repr(s: &str) -> Repr<'_> {
354+
Repr::new(s, Quote::Single)
359355
}
360356

361357
#[derive(Debug, Copy, Clone)]
@@ -423,10 +419,19 @@ pub struct Repr<'a> {
423419
s: &'a str,
424420
// the quote type we prefer to use
425421
quote: Quote,
426-
// the tuple is dquouted, out_len
427422
info: OnceCell<Result<ReprInfo, ReprOverflowError>>,
428423
}
429424

425+
impl<'a> Repr<'a> {
426+
pub fn new(s: &'a str, quote: Quote) -> Self {
427+
Self {
428+
s,
429+
quote,
430+
info: OnceCell::new(),
431+
}
432+
}
433+
}
434+
430435
impl Repr<'_> {
431436
fn get_info(&self) -> Result<ReprInfo, ReprOverflowError> {
432437
*self.info.get_or_init(|| ReprInfo::get(self.s, self.quote))

vm/src/bytesinner.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ impl PyBytesInner {
249249

250250
pub fn repr(&self, class_name: Option<&str>, vm: &VirtualMachine) -> PyResult<String> {
251251
let repr = if let Some(class_name) = class_name {
252-
rustpython_common::bytes::repr_with(&self.elements, &[class_name, "("], ")")
252+
rustpython_common::bytes::repr_with(
253+
&self.elements,
254+
&[class_name, "("],
255+
")",
256+
rustpython_common::str::Quote::Single,
257+
)
253258
} else {
254259
rustpython_common::bytes::repr(&self.elements)
255260
};

0 commit comments

Comments
 (0)