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>,
    },
}
Available on crate feature experimental-inspect only.
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§

Returns the module in which a type is declared.

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

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

The Python Optional type.

The Python Union type.

The Python List type.

The Python Sequence type.

The Python Set type.

The Python FrozenSet type.

The Python Iterable type.

The Python Iterator type.

The Python Dict type.

The Python Mapping type.

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

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Checks if this value is equivalent to the given key. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.