Skip to content

Commit

Permalink
Convert val_to_log_level
Browse files Browse the repository at this point in the history
[ci skip-build-wheels]
  • Loading branch information
gshuflin committed Oct 12, 2020
1 parent d3799c3 commit 053c7b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rust/engine/src/externs/engine_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl EngineAwareInformation for EngineAwareLevel {
fn retrieve(_types: &Types, value: &Value) -> Option<Level> {
let new_level_val = externs::call_method(value.as_ref(), "level", &[]).ok()?;
let new_level_val = externs::check_for_python_none(new_level_val)?;
externs::val_to_log_level(&new_level_val.into()).ok()
externs::val_to_log_level(&new_level_val).ok()
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/rust/engine/src/externs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ pub fn project_u64(value: &Value, field: &str) -> u64 {
getattr(value.as_ref(), field).unwrap()
}

pub fn project_maybe_u64(value: &Value, field: &str) -> Result<u64, String> {
getattr(value.as_ref(), field)
}

pub fn project_f64(value: &Value, field: &str) -> f64 {
getattr(value.as_ref(), field).unwrap()
}
Expand Down Expand Up @@ -305,11 +301,11 @@ pub fn val_to_str(obj: &PyObject) -> String {
pystring.to_string(py).unwrap().into_owned()
}

pub fn val_to_log_level(val: &Value) -> Result<log::Level, String> {
let res: Result<PythonLogLevel, String> = project_maybe_u64(&val, "_level").and_then(|n: u64| {
pub fn val_to_log_level(obj: &PyObject) -> Result<log::Level, String> {
let res: Result<PythonLogLevel, String> = getattr(obj, "_level").and_then(|n: u64| {
n.try_into()
.map_err(|e: num_enum::TryFromPrimitiveError<_>| {
format!("Could not parse {:?} as a LogLevel: {}", val, e)
format!("Could not parse {:?} as a LogLevel: {}", val_to_str(obj), e)
})
});
res.map(|py_level| py_level.into())
Expand Down
3 changes: 2 additions & 1 deletion src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ impl MultiPlatformExecuteProcess {
};

let description = externs::project_str(&value, "description");
let level = externs::val_to_log_level(&externs::project_ignoring_type(&value, "level"))?;
let level =
externs::val_to_log_level(&externs::project_ignoring_type(&value, "level").as_ref())?;

let append_only_caches = externs::project_frozendict(&value, "append_only_caches")
.into_iter()
Expand Down

0 comments on commit 053c7b1

Please sign in to comment.