Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed Oct 12, 2023
1 parent a25c916 commit 62c0691
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/input/input_python.rs
Expand Up @@ -255,17 +255,9 @@ impl<'a> Input<'a> for PyAny {
|| self.is_instance(decimal_type.as_ref(py)).unwrap_or_default()
} {
Ok(self.str()?.into())
} else if let Some(enum_val) = maybe_as_enum(self.py(), self) {
} else if let Some(enum_val) = maybe_as_enum(self) {
return Ok(enum_val.str()?.into());
} else {
// let py = self.py();
// // Enum value not inherited from `str`
// let enum_object = py.import("enum").unwrap().getattr("EnumMeta").unwrap().to_object(py);
// let meta_type = self.get_type().get_type();
// if meta_type.is(&enum_object) {
// let val = self.getattr(intern!(py, "value"))?;
// return Ok(val.str()?.into());
// }
Err(ValError::new(ErrorTypeDefaults::StringType, self))
}
}
Expand Down Expand Up @@ -349,7 +341,7 @@ impl<'a> Input<'a> for PyAny {
decimal_as_int(self.py(), self, decimal)
} else if let Ok(float) = self.extract::<f64>() {
float_as_int(self, float)
} else if let Some(enum_val) = maybe_as_enum(self.py(), self) {
} else if let Some(enum_val) = maybe_as_enum(self) {
Ok(EitherInt::Py(enum_val))
} else {
Err(ValError::new(ErrorTypeDefaults::IntType, self))
Expand Down Expand Up @@ -771,7 +763,8 @@ fn maybe_as_string(v: &PyAny, unicode_error: ErrorType) -> ValResult<Option<Cow<
}

/// Utility for extracting an enum value, if possible.
fn maybe_as_enum<'a>(py: Python<'a>, v: &'a PyAny) -> Option<&'a PyAny> {
fn maybe_as_enum<'a>(v: &'a PyAny) -> Option<&'a PyAny> {
let py = v.py();
let enum_meta_object = py.import("enum").unwrap().getattr("EnumMeta").unwrap().to_object(py);
let meta_type = v.get_type().get_type();
if meta_type.is(&enum_meta_object) {
Expand Down

0 comments on commit 62c0691

Please sign in to comment.