diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 14667a69e8..c302381e34 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -190,7 +190,8 @@ impl ByteInnerPaddingOptions { .ok_or_else(|| { vm.new_type_error(format!( "{}() argument 2 must be a byte string of length 1, not {}", - fn_name, &v + fn_name, + v.class().name() )) })? } else { diff --git a/vm/src/macros.rs b/vm/src/macros.rs index 013926aa8e..21db2e40eb 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -101,7 +101,7 @@ macro_rules! py_namespace { /// let int_value = match_class!(match obj { /// i @ PyInt => i.as_bigint().clone(), /// f @ PyFloat => f.to_f64().to_bigint().unwrap(), -/// obj => panic!("non-numeric object {}", obj), +/// obj => panic!("non-numeric object {:?}", obj), /// }); /// /// assert!(int_value.is_zero()); diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index 4d178ea656..14b9d61df3 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -29,18 +29,6 @@ Basically reference counting, but then done by rust. /// since exceptions are also python objects. pub type PyResult = Result; // A valid value, or an exception -// TODO: remove these 2 impls -impl fmt::Display for PyObjectRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - (**self).fmt(f) - } -} -impl fmt::Display for PyObject { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "'{}' object", self.class().name()) - } -} - impl fmt::Display for PyRef where T: PyObjectPayload + fmt::Display, diff --git a/vm/src/protocol/object.rs b/vm/src/protocol/object.rs index 4869d92862..54f4d84b13 100644 --- a/vm/src/protocol/object.rs +++ b/vm/src/protocol/object.rs @@ -184,7 +184,13 @@ impl PyObject { pub fn generic_getattr(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult { self.generic_getattr_opt(name.clone(), None, vm)? - .ok_or_else(|| vm.new_attribute_error(format!("{} has no attribute '{}'", self, name))) + .ok_or_else(|| { + vm.new_attribute_error(format!( + "'{}' object has no attribute '{}'", + self.class().name(), + name + )) + }) } /// CPython _PyObject_GenericGetAttrWithDict @@ -527,8 +533,12 @@ impl PyObject { } pub fn length(&self, vm: &VirtualMachine) -> PyResult { - self.length_opt(vm) - .ok_or_else(|| vm.new_type_error(format!("object of type '{}' has no len()", &self)))? + self.length_opt(vm).ok_or_else(|| { + vm.new_type_error(format!( + "object of type '{}' has no len()", + self.class().name() + )) + })? } pub fn get_item(&self, needle: &K, vm: &VirtualMachine) -> PyResult { diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 4715473d7f..890c9a71c8 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -349,7 +349,7 @@ pub(crate) mod _thread { .ok_or_else(|| { vm.new_attribute_error(format!( "{} has no attribute '{}'", - zelf.as_object(), + zelf.class().name(), attr )) }) @@ -367,7 +367,7 @@ pub(crate) mod _thread { if attr.as_str() == "__dict__" { Err(vm.new_attribute_error(format!( "{} attribute '__dict__' is read-only", - zelf.as_object() + zelf.class().name() ))) } else { let dict = zelf.ldict(vm); diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 0e13339f84..d169754251 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -416,7 +416,7 @@ impl VirtualMachine { .unwrap_or_else(|_| panic!("unable to import {}", module)); let class = module .get_attr(class, self) - .unwrap_or_else(|_| panic!("module {} has no class {}", module, class)); + .unwrap_or_else(|_| panic!("module {:?} has no class {}", module, class)); class.downcast().expect("not a class") }