pyo3::inspect::types

Enum TypeInfo

Source
pub enum TypeInfo {
    Any,
    None,
    NoReturn,
    Callable(Option<Vec<TypeInfo>>, Box<TypeInfo>),
    Tuple(Option<Vec<TypeInfo>>),
    UnsizedTypedTuple(Box<TypeInfo>),
    Class {
        module: ModuleName,
        name: Cow<'static, str>,
        type_vars: Vec<TypeInfo>,
    },
}
Expand description

Designation of a Python type.

This enum is used to handle advanced types, such as types with generics. Its Display implementation can be used to convert to the type hint notation (e.g. List[int]).

Variants§

§

Any

The type typing.Any, which represents any possible value (unknown type).

§

None

The type typing.None.

§

NoReturn

The type typing.NoReturn, which represents functions that never return (they can still panic / throw, similar to never in Rust).

§

Callable(Option<Vec<TypeInfo>>, Box<TypeInfo>)

The type typing.Callable.

The first argument represents the parameters of the callable:

  • Some of a vector of types to represent the signature,
  • None if the signature is unknown (allows any number of arguments with type Any).

The second argument represents the return type.

§

Tuple(Option<Vec<TypeInfo>>)

The type typing.tuple.

The argument represents the contents of the tuple:

  • Some of a vector of types to represent the accepted types,
  • Some of an empty vector for the empty tuple,
  • None if the number and type of accepted values is unknown.

If the number of accepted values is unknown, but their type is, use Self::UnsizedTypedTuple.

§

UnsizedTypedTuple(Box<TypeInfo>)

The type typing.Tuple.

Use this variant to represent a tuple of unknown size but of known types.

If the type is unknown, or if the number of elements is known, use Self::Tuple.

§

Class

A Python class.

Fields

§module: ModuleName

The module this class comes from.

§name: Cow<'static, str>

The name of this class, as it appears in a type hint.

§type_vars: Vec<TypeInfo>

The generics accepted by this class (empty vector if this class is not generic).

Implementations§

Source§

impl TypeInfo

Source

pub fn module_name(&self) -> Option<&str>

Returns the module in which a type is declared.

Returns None if the type is declared in the current module.

Source

pub fn name(&self) -> Cow<'_, str>

Returns the name of a type.

The name of a type is the part of the hint that is not generic (e.g. List instead of List[int]).

Source§

impl TypeInfo

Source

pub fn optional_of(t: TypeInfo) -> TypeInfo

The Python Optional type.

Source

pub fn union_of(types: &[TypeInfo]) -> TypeInfo

The Python Union type.

Source

pub fn list_of(t: TypeInfo) -> TypeInfo

The Python List type.

Source

pub fn sequence_of(t: TypeInfo) -> TypeInfo

The Python Sequence type.

Source

pub fn set_of(t: TypeInfo) -> TypeInfo

The Python Set type.

Source

pub fn frozen_set_of(t: TypeInfo) -> TypeInfo

The Python FrozenSet type.

Source

pub fn iterable_of(t: TypeInfo) -> TypeInfo

The Python Iterable type.

Source

pub fn iterator_of(t: TypeInfo) -> TypeInfo

The Python Iterator type.

Source

pub fn dict_of(k: TypeInfo, v: TypeInfo) -> TypeInfo

The Python Dict type.

Source

pub fn mapping_of(k: TypeInfo, v: TypeInfo) -> TypeInfo

The Python Mapping type.

Source

pub fn builtin(name: &'static str) -> TypeInfo

Convenience factory for non-generic builtins (e.g. int).

Trait Implementations§

Source§

impl Clone for TypeInfo

Source§

fn clone(&self) -> TypeInfo

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TypeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TypeInfo

Source§

fn eq(&self, other: &TypeInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TypeInfo

Source§

impl StructuralPartialEq for TypeInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Ungil for T
where T: Send,