Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions compiler/porcelain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,14 @@ pub fn compile_symtable(
mode: compile::Mode,
source_path: &str,
) -> Result<symboltable::SymbolTable, CompileError> {
macro_rules! try_parse {
($x:expr) => {
match $x {
Ok(x) => x,
Err(e) => return Err(CompileError::from_parse(e, source, source_path.to_owned())),
}
};
}
let parse_err = |e| CompileError::from_parse(e, source, source_path.to_owned());
let res = match mode {
compile::Mode::Exec | compile::Mode::Single | compile::Mode::BlockExpr => {
let ast = try_parse!(parser::parse_program(source));
let ast = parser::parse_program(source).map_err(parse_err)?;
symboltable::make_symbol_table(&ast)
}
compile::Mode::Eval => {
let expr = try_parse!(parser::parse_expression(source));
let expr = parser::parse_expression(source).map_err(parse_err)?;
symboltable::make_symbol_table_expr(&expr)
}
};
Expand Down
3 changes: 2 additions & 1 deletion vm/src/bytesinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 0 additions & 12 deletions vm/src/object/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ Basically reference counting, but then done by rust.
/// since exceptions are also python objects.
pub type PyResult<T = PyObjectRef> = Result<T, PyBaseExceptionRef>; // 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<T: fmt::Display> fmt::Display for PyRef<T>
where
T: PyObjectPayload + fmt::Display,
Expand Down
16 changes: 13 additions & 3 deletions vm/src/protocol/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -527,8 +533,12 @@ impl PyObject {
}

pub fn length(&self, vm: &VirtualMachine) -> PyResult<usize> {
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<K: DictKey + ?Sized>(&self, needle: &K, vm: &VirtualMachine) -> PyResult {
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
})
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down