FromPyObject

Trait FromPyObject 

Source
pub trait FromPyObject<'a, 'py>: Sized {
    type Error: Into<PyErr>;

    const INPUT_TYPE: &'static str = "typing.Any";

    // Required method
    fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>;

    // Provided methods
    fn type_input() -> TypeInfo { ... }
    fn as_local_tz(_: Token) -> Option<Self> { ... }
}
Expand description

Extract a type from a Python object.

Normal usage is through the extract methods on Bound, Borrowed and Py, which forward to this trait.

§Examples

use pyo3::prelude::*;
use pyo3::types::PyString;

Python::attach(|py| {
    // Calling `.extract()` on a `Bound` smart pointer
    let obj: Bound<'_, PyString> = PyString::new(py, "blah");
    let s: String = obj.extract()?;

    // Calling `.extract(py)` on a `Py` smart pointer
    let obj: Py<PyString> = obj.unbind();
    let s: String = obj.extract(py)?;
})

Note: Depending on the Python version and implementation, some FromPyObject implementations may produce a result that borrows into the Python type. This is described by the input lifetime 'a of obj.

Types that must not borrow from the input can use FromPyObjectOwned as a restriction. This is most often the case for collection types. See its documentation for more details.

§How to implement FromPyObject?

§#[derive(FromPyObject)]

The simplest way to implement FromPyObject for a custom type is to make use of our derive macro.

use pyo3::prelude::*;

#[derive(FromPyObject)]
struct MyObject {
    msg: String,
    list: Vec<u32>
}

By default this will try to extract each field from the Python object by attribute access, but this can be customized. For more information about the derive macro, its configuration as well as its working principle for other types, take a look at the guide.

In case the derive macro is not sufficient or can not be used for some other reason, FromPyObject can be implemented manually. In the following types without lifetime parameters are handled first, because they are a little bit simpler. Types with lifetime parameters are explained below.

§Manual implementation for types without lifetime

Types that do not contain lifetime parameters are unable to borrow from the Python object, so the lifetimes of FromPyObject can be elided:

use pyo3::prelude::*;

struct MyObject {
    msg: String,
    list: Vec<u32>
}

impl FromPyObject<'_, '_> for MyObject {
    type Error = PyErr;

    fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error> {
        Ok(MyObject {
            msg: obj.getattr("msg")?.extract()?,
            list: obj.getattr("list")?.extract()?,
        })
    }
}

This is basically what the derive macro above expands to.

§Manual implementation for types with lifetime paramaters

For types that contain lifetimes, these lifetimes need to be bound to the corresponding FromPyObject lifetime. This is roughly how the extraction of a typed Bound is implemented within PyO3.

use pyo3::prelude::*;
use pyo3::types::PyString;

struct MyObject<'py>(Bound<'py, PyString>);

impl<'py> FromPyObject<'_, 'py> for MyObject<'py> {
    type Error = PyErr;

    fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error> {
        Ok(MyObject(obj.cast()?.to_owned()))
    }
}

§Details

Cow<'a, str> is an example of an output type that may or may not borrow from the input lifetime 'a. Which variant will be produced depends on the runtime type of the Python object. For a Python byte string, the existing string data can be borrowed for 'a into a Cow::Borrowed. For a Python Unicode string, the data may have to be reencoded to UTF-8, and copied into a Cow::Owned. It does not depend on the Python lifetime 'py.

The output type may also depend on the Python lifetime 'py. This allows the output type to keep interacting with the Python interpreter. See also Bound<'py, T>.

Provided Associated Constants§

Source

const INPUT_TYPE: &'static str = "typing.Any"

Available on crate feature experimental-inspect only.

Provides the type hint information for this type when it appears as an argument.

For example, Vec<u32> would be collections.abc.Sequence[int]. The default value is typing.Any, which is correct for any type.

Required Associated Types§

Source

type Error: Into<PyErr>

The type returned in the event of a conversion error.

For most use cases defaulting to PyErr here is perfectly acceptable. Using a custom error type can be used to avoid having to create a Python exception object in the case where that exception never reaches Python. This may lead to slightly better performance under certain conditions.

§Note

Unfortunately Try and thus ? is based on From, not Into, so implementations may need to use .map_err(Into::into) sometimes to convert a generic Error into a PyErr.

Required Methods§

Source

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Extracts Self from the bound smart pointer obj.

Users are advised against calling this method directly: instead, use this via Bound<'_, PyAny>::extract or Py::extract.

Provided Methods§

Source

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.

Extracts the type hint information for this type when it appears as an argument.

For example, Vec<u32> would return Sequence[int]. The default implementation returns Any, which is correct for any type.

For most types, the return value for this method will be identical to that of IntoPyObject::type_output. It may be different for some types, such as Dict, to allow duck-typing: functions return Dict but take Mapping as argument.

Source

fn as_local_tz(_: Token) -> Option<Self>

Available on crate feature chrono-local only.

Helper used to make a specialized path in extracting DateTime<Tz> where Tz is chrono::Local, which will accept “naive” datetime objects as being in the local timezone.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromPyObject<'_, '_> for IpAddr

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for Tz

Available on Py_3_9 and crate feature chrono-tz only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for bool

Converts a Python bool to a Rust bool.

Fails with TypeError if the input is not a Python bool.

Source§

const INPUT_TYPE: &'static str = "bool"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for char

Source§

const INPUT_TYPE: &'static str = "str"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for i128

Available on non-Py_LIMITED_API only.
Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<i128, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for u64

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<u64, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for u128

Available on non-Py_LIMITED_API only.
Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<u128, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for usize

Source§

const INPUT_TYPE: &'static str = u64::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for CString

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for String

Allows extracting strings from Python objects. Accepts Python str and unicode objects.

Source§

const INPUT_TYPE: &'static str = "str"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for Duration

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for OsString

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for PathBuf

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for SystemTime

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for BigDecimal

Available on crate feature bigdecimal only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> PyResult<Self>

Source§

impl FromPyObject<'_, '_> for NaiveDate

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for NaiveDateTime

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(dt: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for NaiveTime

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for FixedOffset

Available on crate feature chrono only.
Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Convert python tzinfo to rust FixedOffset.

Note that the conversion will result in precision lost in microseconds as chrono offset does not supports microseconds.

Source§

type Error = PyErr

Source§

impl FromPyObject<'_, '_> for Local

Available on crate features chrono and chrono-local only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> PyResult<Local>

Source§

fn as_local_tz(_: Token) -> Option<Self>

Source§

impl FromPyObject<'_, '_> for Utc

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for ISOWeekDate

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> PyResult<Self>

Source§

impl FromPyObject<'_, '_> for Complex<f32>

Available on crate feature num-complex only.
Source§

impl FromPyObject<'_, '_> for Complex<f64>

Available on crate feature num-complex only.
Source§

impl FromPyObject<'_, '_> for Decimal

Available on crate feature rust_decimal only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for Date

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for Duration

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for OffsetDateTime

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for PrimitiveDateTime

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(dt: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for Time

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for UtcDateTime

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for UtcOffset

Available on crate feature time only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl FromPyObject<'_, '_> for Uuid

Available on crate feature uuid only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> PyResult<Self>

Source§

impl FromPyObject<'_, '_> for NonZeroI8

Source§

const INPUT_TYPE: &'static str = i8::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroI16

Source§

const INPUT_TYPE: &'static str = i16::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroI32

Source§

const INPUT_TYPE: &'static str = i32::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroI64

Source§

const INPUT_TYPE: &'static str = i64::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroI128

Source§

const INPUT_TYPE: &'static str = i128::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroIsize

Source§

const INPUT_TYPE: &'static str = isize::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroU8

Source§

const INPUT_TYPE: &'static str = u8::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroU16

Source§

const INPUT_TYPE: &'static str = u16::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroU32

Source§

const INPUT_TYPE: &'static str = u32::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroU64

Source§

const INPUT_TYPE: &'static str = u64::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroU128

Source§

const INPUT_TYPE: &'static str = u128::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for NonZeroUsize

Source§

const INPUT_TYPE: &'static str = usize::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl FromPyObject<'_, '_> for Duration

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a> FromPyObject<'a, '_> for &'a str

Available on Py_3_10 or non-Py_LIMITED_API only.
Source§

const INPUT_TYPE: &'static str = "str"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a> FromPyObject<'a, '_> for &'a CStr

Available on Py_3_10 or non-Py_LIMITED_API only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a> FromPyObject<'a, '_> for Cow<'a, str>

Source§

const INPUT_TYPE: &'static str = "str"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a> FromPyObject<'a, '_> for Cow<'a, CStr>

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a> FromPyObject<'a, '_> for Cow<'a, OsStr>

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a> FromPyObject<'a, '_> for Cow<'a, Path>

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, '_, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for &'a [u8]

Source§

type Error = CastError<'a, 'py>

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py> FromPyObject<'a, 'py> for Cow<'a, [u8]>

Special-purpose trait impl to efficiently handle both bytes and bytearray

If the source object is a bytes object, the Cow will be borrowed and pointing into the source object, and no copying or heap allocations will happen. If it is a bytearray, its contents will be copied to an owned Cow.

Source§

type Error = CastError<'a, 'py>

Source§

fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py> FromPyObject<'a, 'py> for f32

Source§

const INPUT_TYPE: &'static str = "float"

Available on crate feature experimental-inspect only.
Source§

type Error = <f64 as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py> FromPyObject<'a, 'py> for Bytes

Available on crate feature bytes only.
Source§

type Error = CastError<'a, 'py>

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for Timestamp

Available on crate feature jiff-02 only.
Source§

type Error = <Zoned as FromPyObject<'a, 'py>>::Error

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for NotNan<f32>

Available on crate feature ordered-float only.
Source§

type Error = <f32 as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for NotNan<f64>

Available on crate feature ordered-float only.
Source§

type Error = <f64 as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for OrderedFloat<f32>

Available on crate feature ordered-float only.
Source§

type Error = <f32 as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for OrderedFloat<f64>

Available on crate feature ordered-float only.
Source§

type Error = <f64 as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py, L, R> FromPyObject<'a, 'py> for Either<L, R>
where L: FromPyObject<'a, 'py>, R: FromPyObject<'a, 'py>,

Available on crate feature either only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0,)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>, T7: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>, T7: FromPyObject<'a, 'py>, T8: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>, T7: FromPyObject<'a, 'py>, T8: FromPyObject<'a, 'py>, T9: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>, T7: FromPyObject<'a, 'py>, T8: FromPyObject<'a, 'py>, T9: FromPyObject<'a, 'py>, T10: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T0: FromPyObject<'a, 'py>, T1: FromPyObject<'a, 'py>, T2: FromPyObject<'a, 'py>, T3: FromPyObject<'a, 'py>, T4: FromPyObject<'a, 'py>, T5: FromPyObject<'a, 'py>, T6: FromPyObject<'a, 'py>, T7: FromPyObject<'a, 'py>, T8: FromPyObject<'a, 'py>, T9: FromPyObject<'a, 'py>, T10: FromPyObject<'a, 'py>, T11: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for Option<T>
where T: FromPyObject<'a, 'py>,

Source§

type Error = <T as FromPyObject<'a, 'py>>::Error

Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'a, 'py, T: FromPyObject<'a, 'py>> FromPyObject<'a, 'py> for Cell<T>

Source§

const INPUT_TYPE: &'static str = T::INPUT_TYPE

Available on crate feature experimental-inspect only.
Source§

type Error = <T as FromPyObject<'a, 'py>>::Error

Source§

fn extract(ob: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for f64

Source§

const INPUT_TYPE: &'static str = "float"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for i8

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for i16

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for i32

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for i64

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for isize

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for u8

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for u16

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for u32

Source§

const INPUT_TYPE: &'static str = "int"

Available on crate feature experimental-inspect only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py> FromPyObject<'_, 'py> for Date

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for DateTime

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(dt: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for Time

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for SignedDuration

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for Span

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for Offset

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for TimeZone

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for Zoned

Available on crate feature jiff-02 only.
Source§

type Error = PyErr

Source§

fn extract(dt: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py> FromPyObject<'_, 'py> for BigInt

Available on crate feature num-bigint only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<BigInt, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for BigUint

Available on crate feature num-bigint only.
Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<i8>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<i16>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<i32>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<i64>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<isize>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py> FromPyObject<'_, 'py> for Ratio<BigInt>

Available on crate feature num-rational only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py, A> FromPyObject<'_, 'py> for SmallVec<A>
where A: Array, A::Item: FromPyObjectOwned<'py>,

Available on crate feature smallvec only.
Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, K> FromPyObject<'_, 'py> for BTreeSet<K>
where K: FromPyObjectOwned<'py> + Ord,

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, K, S> FromPyObject<'_, 'py> for HashSet<K, S>
where K: FromPyObjectOwned<'py> + Eq + Hash, S: BuildHasher + Default,

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, K, S> FromPyObject<'_, 'py> for HashSet<K, S>
where K: FromPyObjectOwned<'py> + Eq + Hash, S: BuildHasher + Default,

Available on crate feature hashbrown only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py, K, V> FromPyObject<'_, 'py> for BTreeMap<K, V>
where K: FromPyObjectOwned<'py> + Ord, V: FromPyObjectOwned<'py>,

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, PyErr>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, K, V, S> FromPyObject<'_, 'py> for HashMap<K, V, S>
where K: FromPyObjectOwned<'py> + Eq + Hash, V: FromPyObjectOwned<'py>, S: BuildHasher + Default,

Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, K, V, S> FromPyObject<'_, 'py> for HashMap<K, V, S>
where K: FromPyObjectOwned<'py> + Eq + Hash, V: FromPyObjectOwned<'py>, S: BuildHasher + Default,

Available on crate feature hashbrown only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, PyErr>

Source§

impl<'py, K, V, S> FromPyObject<'_, 'py> for IndexMap<K, V, S>
where K: FromPyObjectOwned<'py> + Eq + Hash, V: FromPyObjectOwned<'py>, S: BuildHasher + Default,

Available on crate feature indexmap only.
Source§

type Error = PyErr

Source§

fn extract(ob: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Source§

impl<'py, T> FromPyObject<'_, 'py> for Vec<T>
where T: FromPyObjectOwned<'py>,

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

fn type_input() -> TypeInfo

Available on crate feature experimental-inspect only.
Source§

impl<'py, T, const N: usize> FromPyObject<'_, 'py> for [T; N]
where T: FromPyObjectOwned<'py>,

Source§

type Error = PyErr

Source§

fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self>

Source§

impl<'py, Tz> FromPyObject<'_, 'py> for DateTime<Tz>
where Tz: TimeZone + FromPyObjectOwned<'py>,

Available on crate feature chrono only.
Source§

type Error = PyErr

Source§

fn extract(dt: Borrowed<'_, 'py, PyAny>) -> Result<Self, Self::Error>

Implementors§

Source§

impl FromPyObject<'_, '_> for PyBackedStr

Source§

impl<'a, 'py> FromPyObject<'a, 'py> for PyBackedBytes

Source§

type Error = CastError<'a, 'py>

Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for PyRef<'py, T>
where T: PyClass,

Source§

const INPUT_TYPE: &'static str = <T as crate::impl_::pyclass::PyClassImpl>::TYPE_NAME

Source§

type Error = PyClassGuardError<'a, 'py>

Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for PyRefMut<'py, T>
where T: PyClass<Frozen = False>,

Source§

const INPUT_TYPE: &'static str = <T as crate::impl_::pyclass::PyClassImpl>::TYPE_NAME

Source§

type Error = PyClassGuardMutError<'a, 'py>

Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for Bound<'py, T>
where T: PyTypeCheck + 'a,

Source§

const INPUT_TYPE: &'static str = T::PYTHON_TYPE

Source§

type Error = CastError<'a, 'py>

Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for Py<T>
where T: PyTypeCheck + 'a,

Source§

const INPUT_TYPE: &'static str = T::PYTHON_TYPE

Source§

type Error = CastError<'a, 'py>

Source§

impl<'a, 'py, T> FromPyObject<'a, 'py> for T
where T: PyClass + Clone + ExtractPyClassWithClone,

Source§

const INPUT_TYPE: &'static str = <T as crate::impl_::pyclass::PyClassImpl>::TYPE_NAME

Source§

type Error = PyClassGuardError<'a, 'py>

Source§

impl<'a, 'py, T: PyClass> FromPyObject<'a, 'py> for PyClassGuard<'a, T>

Source§

impl<'a, 'py, T: PyClass<Frozen = False>> FromPyObject<'a, 'py> for PyClassGuardMut<'a, T>

Source§

impl<T: Element> FromPyObject<'_, '_> for PyBuffer<T>

Available on non-Py_LIMITED_API or Py_3_11 only.