Fixed tests after modifying TypeErrors originating from structs. Started work on TypeError message on Enums

This commit is contained in:
R2D2 2021-05-31 00:28:53 +02:00
parent 1843ff20fd
commit 4a99bfaaba
3 changed files with 11 additions and 4 deletions

View File

@ -58,9 +58,13 @@ impl<'a> Enum<'a> {
let maybe_ret = || -> pyo3::PyResult<Self> {
#struct_derive
}();
if maybe_ret.is_ok() {
return maybe_ret
}
if let Err(inner) = maybe_ret {
err_reasons.push(format!("{}", inner))
}
);
var_extracts.push(ext);
@ -74,13 +78,16 @@ impl<'a> Enum<'a> {
} else {
error_names
};
let ty_name: String = self.enum_ident.to_string();
quote!(
let mut err_reasons: Vec<String> = Vec::new();
#(#var_extracts)*
let type_name = obj.get_type().name()?;
let err_msg = format!("In {} : '{}' object cannot be converted to '{}'",
self.enum_ident,
let err_msg = format!("Failed to extract type {}\n\nCaused by:\nTypeError: '{}' object cannot be converted to '{}'",
#ty_name,
type_name,
#error_names);
println!("{:?}", err_reasons);
Err(pyo3::exceptions::PyTypeError::new_err(err_msg))
)
}

View File

@ -296,7 +296,7 @@ fn test_err_rename() {
assert!(f.is_err());
assert_eq!(
f.unwrap_err().to_string(),
"TypeError: 'dict' object cannot be converted to 'Union[str, uint, int]'"
"TypeError: Failed to extract type Bar\n\nCaused by:\nTypeError: 'dict' object cannot be converted to 'Union[str, uint, int]'"
);
}

View File

@ -84,7 +84,7 @@ error: transparent structs and variants can only have 1 field
70 | | },
| |_____^
error: expected one of: `attribute`, `item`, `from_py_with`
error: expected one of: `attribute`, `item`, `from_py_with`, `conversion_error`
--> $DIR/invalid_frompy_derive.rs:76:12
|
76 | #[pyo3(attr)]