pub unsafe trait PyTypeInfo: Sized {
const NAME: &'static str;
const MODULE: Option<&'static str>;
const TYPE_HINT: PyStaticExpr = _;
// Required method
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject;
// Provided methods
fn type_object(py: Python<'_>) -> Bound<'_, PyType> { ... }
fn is_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
}Expand description
Python type information.
All Python native types (e.g., PyDict) and #[pyclass] structs implement this trait.
This trait is marked unsafe because:
- specifying the incorrect layout can lead to memory errors
- the return value of type_object must always point to the same PyTypeObject instance
It is safely implemented by the pyclass macro.
§Safety
Implementations must provide an implementation for type_object_raw which infallibly produces a
non-null pointer to the corresponding Python type object.
is_type_of must only return true for objects which can safely be treated as instances of Self.
is_exact_type_of must only return true for objects whose type is exactly Self.
Required Associated Constants§
Provided Associated Constants§
Sourceconst TYPE_HINT: PyStaticExpr = _
Available on crate feature experimental-inspect only.
const TYPE_HINT: PyStaticExpr = _
experimental-inspect only.Provides the full python type as a type hint.
Required Methods§
Sourcefn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Returns the PyTypeObject instance for this type.
Provided Methods§
Sourcefn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Returns the safe abstraction over the type object.
Sourcefn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
Checks if object is an instance of this type or a subclass of this type.
Sourcefn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
Checks if object is an instance of this type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl PyTypeInfo for CancelledError
impl PyTypeInfo for CancelledError
Source§impl PyTypeInfo for Coroutine
Available on crate feature experimental-async only.
impl PyTypeInfo for Coroutine
experimental-async only.Source§impl PyTypeInfo for IncompleteReadError
impl PyTypeInfo for IncompleteReadError
Source§impl PyTypeInfo for InvalidStateError
impl PyTypeInfo for InvalidStateError
Source§impl PyTypeInfo for LimitOverrunError
impl PyTypeInfo for LimitOverrunError
Source§impl PyTypeInfo for PanicException
impl PyTypeInfo for PanicException
Source§impl PyTypeInfo for PyAny
impl PyTypeInfo for PyAny
Source§impl PyTypeInfo for PyArithmeticError
impl PyTypeInfo for PyArithmeticError
Source§impl PyTypeInfo for PyAssertionError
impl PyTypeInfo for PyAssertionError
Source§impl PyTypeInfo for PyAttributeError
impl PyTypeInfo for PyAttributeError
Source§impl PyTypeInfo for PyBaseException
impl PyTypeInfo for PyBaseException
Source§impl PyTypeInfo for PyBaseExceptionGroup
impl PyTypeInfo for PyBaseExceptionGroup
Source§impl PyTypeInfo for PyBlockingIOError
impl PyTypeInfo for PyBlockingIOError
Source§impl PyTypeInfo for PyBool
impl PyTypeInfo for PyBool
Source§impl PyTypeInfo for PyBrokenPipeError
impl PyTypeInfo for PyBrokenPipeError
Source§impl PyTypeInfo for PyBufferError
impl PyTypeInfo for PyBufferError
Source§impl PyTypeInfo for PyByteArray
impl PyTypeInfo for PyByteArray
Source§impl PyTypeInfo for PyBytes
impl PyTypeInfo for PyBytes
Source§impl PyTypeInfo for PyBytesWarning
impl PyTypeInfo for PyBytesWarning
Source§impl PyTypeInfo for PyCFunction
impl PyTypeInfo for PyCFunction
Source§impl PyTypeInfo for PyCapsule
impl PyTypeInfo for PyCapsule
Source§impl PyTypeInfo for PyChildProcessError
impl PyTypeInfo for PyChildProcessError
Source§impl PyTypeInfo for PyCode
impl PyTypeInfo for PyCode
Source§impl PyTypeInfo for PyComplex
impl PyTypeInfo for PyComplex
Source§impl PyTypeInfo for PyConnectionError
impl PyTypeInfo for PyConnectionError
Source§impl PyTypeInfo for PyConnectionResetError
impl PyTypeInfo for PyConnectionResetError
Source§impl PyTypeInfo for PyDate
impl PyTypeInfo for PyDate
Source§impl PyTypeInfo for PyDateTime
impl PyTypeInfo for PyDateTime
Source§impl PyTypeInfo for PyDelta
impl PyTypeInfo for PyDelta
Source§impl PyTypeInfo for PyDeprecationWarning
impl PyTypeInfo for PyDeprecationWarning
Source§impl PyTypeInfo for PyDict
impl PyTypeInfo for PyDict
Source§impl PyTypeInfo for PyDictItems
impl PyTypeInfo for PyDictItems
Source§impl PyTypeInfo for PyDictKeys
impl PyTypeInfo for PyDictKeys
Source§impl PyTypeInfo for PyDictValues
impl PyTypeInfo for PyDictValues
Source§impl PyTypeInfo for PyEOFError
impl PyTypeInfo for PyEOFError
Source§impl PyTypeInfo for PyEllipsis
impl PyTypeInfo for PyEllipsis
Source§impl PyTypeInfo for PyEncodingWarning
impl PyTypeInfo for PyEncodingWarning
Source§impl PyTypeInfo for PyException
impl PyTypeInfo for PyException
Source§impl PyTypeInfo for PyFileExistsError
impl PyTypeInfo for PyFileExistsError
Source§impl PyTypeInfo for PyFileNotFoundError
impl PyTypeInfo for PyFileNotFoundError
Source§impl PyTypeInfo for PyFloat
impl PyTypeInfo for PyFloat
Source§impl PyTypeInfo for PyFloatingPointError
impl PyTypeInfo for PyFloatingPointError
Source§impl PyTypeInfo for PyFrame
Available on non-GraalPy and non-Py_LIMITED_API and non-PyPy only.
impl PyTypeInfo for PyFrame
GraalPy and non-Py_LIMITED_API and non-PyPy only.Source§impl PyTypeInfo for PyFrozenSet
impl PyTypeInfo for PyFrozenSet
Source§impl PyTypeInfo for PyFunction
impl PyTypeInfo for PyFunction
Source§impl PyTypeInfo for PyFutureWarning
impl PyTypeInfo for PyFutureWarning
Source§impl PyTypeInfo for PyGeneratorExit
impl PyTypeInfo for PyGeneratorExit
Source§impl PyTypeInfo for PyGenericAlias
Available on Py_3_9 only.
impl PyTypeInfo for PyGenericAlias
Py_3_9 only.