Skip to content

Commit 2bb9aee

Browse files
committed
Remove Display impl for PyObject
1 parent b476c56 commit 2bb9aee

6 files changed

Lines changed: 19 additions & 20 deletions

File tree

vm/src/bytesinner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ impl ByteInnerPaddingOptions {
190190
.ok_or_else(|| {
191191
vm.new_type_error(format!(
192192
"{}() argument 2 must be a byte string of length 1, not {}",
193-
fn_name, &v
193+
fn_name,
194+
v.class().name()
194195
))
195196
})?
196197
} else {

vm/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ macro_rules! py_namespace {
101101
/// let int_value = match_class!(match obj {
102102
/// i @ PyInt => i.as_bigint().clone(),
103103
/// f @ PyFloat => f.to_f64().to_bigint().unwrap(),
104-
/// obj => panic!("non-numeric object {}", obj),
104+
/// obj => panic!("non-numeric object {:?}", obj),
105105
/// });
106106
///
107107
/// assert!(int_value.is_zero());

vm/src/object/ext.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ Basically reference counting, but then done by rust.
2929
/// since exceptions are also python objects.
3030
pub type PyResult<T = PyObjectRef> = Result<T, PyBaseExceptionRef>; // A valid value, or an exception
3131

32-
// TODO: remove these 2 impls
33-
impl fmt::Display for PyObjectRef {
34-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35-
(**self).fmt(f)
36-
}
37-
}
38-
impl fmt::Display for PyObject {
39-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40-
write!(f, "'{}' object", self.class().name())
41-
}
42-
}
43-
4432
impl<T: fmt::Display> fmt::Display for PyRef<T>
4533
where
4634
T: PyObjectPayload + fmt::Display,

vm/src/protocol/object.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ impl PyObject {
184184

185185
pub fn generic_getattr(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
186186
self.generic_getattr_opt(name.clone(), None, vm)?
187-
.ok_or_else(|| vm.new_attribute_error(format!("{} has no attribute '{}'", self, name)))
187+
.ok_or_else(|| {
188+
vm.new_attribute_error(format!(
189+
"'{}' object has no attribute '{}'",
190+
self.class().name(),
191+
name
192+
))
193+
})
188194
}
189195

190196
/// CPython _PyObject_GenericGetAttrWithDict
@@ -527,8 +533,12 @@ impl PyObject {
527533
}
528534

529535
pub fn length(&self, vm: &VirtualMachine) -> PyResult<usize> {
530-
self.length_opt(vm)
531-
.ok_or_else(|| vm.new_type_error(format!("object of type '{}' has no len()", &self)))?
536+
self.length_opt(vm).ok_or_else(|| {
537+
vm.new_type_error(format!(
538+
"object of type '{}' has no len()",
539+
self.class().name()
540+
))
541+
})?
532542
}
533543

534544
pub fn get_item<K: DictKey + ?Sized>(&self, needle: &K, vm: &VirtualMachine) -> PyResult {

vm/src/stdlib/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub(crate) mod _thread {
349349
.ok_or_else(|| {
350350
vm.new_attribute_error(format!(
351351
"{} has no attribute '{}'",
352-
zelf.as_object(),
352+
zelf.class().name(),
353353
attr
354354
))
355355
})
@@ -367,7 +367,7 @@ pub(crate) mod _thread {
367367
if attr.as_str() == "__dict__" {
368368
Err(vm.new_attribute_error(format!(
369369
"{} attribute '__dict__' is read-only",
370-
zelf.as_object()
370+
zelf.class().name()
371371
)))
372372
} else {
373373
let dict = zelf.ldict(vm);

vm/src/vm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl VirtualMachine {
416416
.unwrap_or_else(|_| panic!("unable to import {}", module));
417417
let class = module
418418
.get_attr(class, self)
419-
.unwrap_or_else(|_| panic!("module {} has no class {}", module, class));
419+
.unwrap_or_else(|_| panic!("module {:?} has no class {}", module, class));
420420
class.downcast().expect("not a class")
421421
}
422422

0 commit comments

Comments
 (0)