Enum pyo3::inspect::types::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

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).

A Python class.

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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
§

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

§

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

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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,