Function get_optional

Source
pub fn get_optional<T>(
    dict: &Bound<'_, PyDict>,
    key: &str,
) -> PyResult<Option<T>>
where T: for<'py> FromPyObject<'py>,
Expand description

Helper function to get an optional value from a Python dictionary.

§Returns

Returns Some(value) if the key exists and extraction succeeds, None if the key is missing or if the value is Python None, or a PyErr if extraction fails.

§Errors

Returns PyErr if value extraction fails (but not if the key is missing or value is None).