pub unsafe trait PyTypeInfo: Sized {
const NAME: &'static str;
const MODULE: Option<&'static str>;
// Required method
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject;
// Provided methods
fn type_object(py: Python<'_>) -> Bound<'_, PyType> { ... }
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType> { ... }
fn is_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
fn is_exact_type_of_bound(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.
Required Associated Constants§
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 type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
👎Deprecated since 0.23.0: renamed to PyTypeInfo::type_object
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
PyTypeInfo::type_object
Deprecated name for PyTypeInfo::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_type_of_bound(object: &Bound<'_, PyAny>) -> bool
👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_type_of
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_type_of
Deprecated name for PyTypeInfo::is_type_of
.
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.
Sourcefn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_exact_type_of
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
PyTypeInfo::is_exact_type_of
Deprecated name for PyTypeInfo::is_exact_type_of
.
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.
Implementors§
Source§impl PyTypeInfo for Coroutine
Available on crate feature experimental-async
only.
impl PyTypeInfo for Coroutine
experimental-async
only.Source§impl PyTypeInfo for CancelledError
impl PyTypeInfo for CancelledError
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 QueueEmpty
impl PyTypeInfo for QueueEmpty
Source§impl PyTypeInfo for QueueFull
impl PyTypeInfo for QueueFull
Source§impl PyTypeInfo for TimeoutError
impl PyTypeInfo for TimeoutError
Source§impl PyTypeInfo for gaierror
impl PyTypeInfo for gaierror
Source§impl PyTypeInfo for herror
impl PyTypeInfo for herror
Source§impl PyTypeInfo for timeout
impl PyTypeInfo for timeout
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 PyBlockingIOError
impl PyTypeInfo for PyBlockingIOError
Source§impl PyTypeInfo for PyBrokenPipeError
impl PyTypeInfo for PyBrokenPipeError
Source§impl PyTypeInfo for PyBufferError
impl PyTypeInfo for PyBufferError
Source§impl PyTypeInfo for PyBytesWarning
impl PyTypeInfo for PyBytesWarning
Source§impl PyTypeInfo for PyChildProcessError
impl PyTypeInfo for PyChildProcessError
Source§impl PyTypeInfo for PyConnectionError
impl PyTypeInfo for PyConnectionError
Source§impl PyTypeInfo for PyConnectionResetError
impl PyTypeInfo for PyConnectionResetError
Source§impl PyTypeInfo for PyDeprecationWarning
impl PyTypeInfo for PyDeprecationWarning
Source§impl PyTypeInfo for PyEOFError
impl PyTypeInfo for PyEOFError
Source§impl PyTypeInfo for PyEncodingWarning
impl PyTypeInfo for PyEncodingWarning
Source§impl PyTypeInfo for PyEnvironmentError
impl PyTypeInfo for PyEnvironmentError
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 PyFloatingPointError
impl PyTypeInfo for PyFloatingPointError
Source§impl PyTypeInfo for PyFutureWarning
impl PyTypeInfo for PyFutureWarning
Source§impl PyTypeInfo for PyGeneratorExit
impl PyTypeInfo for PyGeneratorExit
Source§impl PyTypeInfo for PyIOError
impl PyTypeInfo for PyIOError
Source§impl PyTypeInfo for PyImportError
impl PyTypeInfo for PyImportError
Source§impl PyTypeInfo for PyImportWarning
impl PyTypeInfo for PyImportWarning
Source§impl PyTypeInfo for PyIndexError
impl PyTypeInfo for PyIndexError
Source§impl PyTypeInfo for PyInterruptedError
impl PyTypeInfo for PyInterruptedError
Source§impl PyTypeInfo for PyIsADirectoryError
impl PyTypeInfo for PyIsADirectoryError
Source§impl PyTypeInfo for PyKeyError
impl PyTypeInfo for PyKeyError
Source§impl PyTypeInfo for PyKeyboardInterrupt
impl PyTypeInfo for PyKeyboardInterrupt
Source§impl PyTypeInfo for PyLookupError
impl PyTypeInfo for PyLookupError
Source§impl PyTypeInfo for PyMemoryError
impl PyTypeInfo for PyMemoryError
Source§impl PyTypeInfo for PyModuleNotFoundError
impl PyTypeInfo for PyModuleNotFoundError
Source§impl PyTypeInfo for PyNameError
impl PyTypeInfo for PyNameError
Source§impl PyTypeInfo for PyNotADirectoryError
impl PyTypeInfo for PyNotADirectoryError
Source§impl PyTypeInfo for PyNotImplementedError
impl PyTypeInfo for PyNotImplementedError
Source§impl PyTypeInfo for PyOSError
impl PyTypeInfo for PyOSError
Source§impl PyTypeInfo for PyOverflowError
impl PyTypeInfo for PyOverflowError
Source§impl PyTypeInfo for PyPermissionError
impl PyTypeInfo for PyPermissionError
Source§impl PyTypeInfo for PyProcessLookupError
impl PyTypeInfo for PyProcessLookupError
Source§impl PyTypeInfo for PyRecursionError
impl PyTypeInfo for PyRecursionError
Source§impl PyTypeInfo for PyReferenceError
impl PyTypeInfo for PyReferenceError
Source§impl PyTypeInfo for PyResourceWarning
impl PyTypeInfo for PyResourceWarning
Source§impl PyTypeInfo for PyRuntimeError
impl PyTypeInfo for PyRuntimeError
Source§impl PyTypeInfo for PyRuntimeWarning
impl PyTypeInfo for PyRuntimeWarning
Source§impl PyTypeInfo for PyStopAsyncIteration
impl PyTypeInfo for PyStopAsyncIteration
Source§impl PyTypeInfo for PyStopIteration
impl PyTypeInfo for PyStopIteration
Source§impl PyTypeInfo for PySyntaxError
impl PyTypeInfo for PySyntaxError
Source§impl PyTypeInfo for PySyntaxWarning
impl PyTypeInfo for PySyntaxWarning
Source§impl PyTypeInfo for PySystemError
impl PyTypeInfo for PySystemError
Source§impl PyTypeInfo for PySystemExit
impl PyTypeInfo for PySystemExit
Source§impl PyTypeInfo for PyTimeoutError
impl PyTypeInfo for PyTimeoutError
Source§impl PyTypeInfo for PyTypeError
impl PyTypeInfo for PyTypeError
Source§impl PyTypeInfo for PyUnboundLocalError
impl PyTypeInfo for PyUnboundLocalError
Source§impl PyTypeInfo for PyUnicodeDecodeError
impl PyTypeInfo for PyUnicodeDecodeError
Source§impl PyTypeInfo for PyUnicodeEncodeError
impl PyTypeInfo for PyUnicodeEncodeError
Source§impl PyTypeInfo for PyUnicodeError
impl PyTypeInfo for PyUnicodeError
Source§impl PyTypeInfo for PyUnicodeTranslateError
impl PyTypeInfo for PyUnicodeTranslateError
Source§impl PyTypeInfo for PyUnicodeWarning
impl PyTypeInfo for PyUnicodeWarning
Source§impl PyTypeInfo for PyUserWarning
impl PyTypeInfo for PyUserWarning
Source§impl PyTypeInfo for PyValueError
impl PyTypeInfo for PyValueError
Source§impl PyTypeInfo for PyWarning
impl PyTypeInfo for PyWarning
Source§impl PyTypeInfo for PyZeroDivisionError
impl PyTypeInfo for PyZeroDivisionError
Source§impl PyTypeInfo for PanicException
impl PyTypeInfo for PanicException
Source§impl PyTypeInfo for PyAny
impl PyTypeInfo for PyAny
Source§impl PyTypeInfo for PyBool
impl PyTypeInfo for PyBool
Source§impl PyTypeInfo for PyByteArray
impl PyTypeInfo for PyByteArray
Source§impl PyTypeInfo for PyBytes
impl PyTypeInfo for PyBytes
Source§impl PyTypeInfo for PyCFunction
impl PyTypeInfo for PyCFunction
Source§impl PyTypeInfo for PyCapsule
impl PyTypeInfo for PyCapsule
Source§impl PyTypeInfo for PyCode
Available on non-Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.
impl PyTypeInfo for PyCode
Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.Source§impl PyTypeInfo for PyComplex
impl PyTypeInfo for PyComplex
Source§impl PyTypeInfo for PyDate
Available on non-Py_LIMITED_API
only.
impl PyTypeInfo for PyDate
Py_LIMITED_API
only.Source§impl PyTypeInfo for PyDateTime
Available on non-Py_LIMITED_API
only.
impl PyTypeInfo for PyDateTime
Py_LIMITED_API
only.Source§impl PyTypeInfo for PyDelta
Available on non-Py_LIMITED_API
only.
impl PyTypeInfo for PyDelta
Py_LIMITED_API
only.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 PyEllipsis
impl PyTypeInfo for PyEllipsis
Source§impl PyTypeInfo for PyFloat
impl PyTypeInfo for PyFloat
Source§impl PyTypeInfo for PyFrame
Available on non-Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.
impl PyTypeInfo for PyFrame
Py_LIMITED_API
and non-PyPy
and non-GraalPy
only.Source§impl PyTypeInfo for PyFrozenSet
impl PyTypeInfo for PyFrozenSet
Source§impl PyTypeInfo for PyFunction
impl PyTypeInfo for PyFunction
Source§impl PyTypeInfo for PyInt
impl PyTypeInfo for PyInt
Source§impl PyTypeInfo for PyList
impl PyTypeInfo for PyList
Source§impl PyTypeInfo for PyMappingProxy
impl PyTypeInfo for PyMappingProxy
Source§impl PyTypeInfo for PyMemoryView
impl PyTypeInfo for PyMemoryView
Source§impl PyTypeInfo for PyModule
impl PyTypeInfo for PyModule
Source§impl PyTypeInfo for PyNone
impl PyTypeInfo for PyNone
Source§impl PyTypeInfo for PyNotImplemented
impl PyTypeInfo for PyNotImplemented
Source§impl PyTypeInfo for PySet
impl PyTypeInfo for PySet
Source§impl PyTypeInfo for PySlice
impl PyTypeInfo for PySlice
Source§impl PyTypeInfo for PyString
impl PyTypeInfo for PyString
Source§impl PyTypeInfo for PySuper
Available on neither PyPy
nor GraalPy
.
impl PyTypeInfo for PySuper
PyPy
nor GraalPy
.Source§impl PyTypeInfo for PyTime
Available on non-Py_LIMITED_API
only.
impl PyTypeInfo for PyTime
Py_LIMITED_API
only.Source§impl PyTypeInfo for PyTraceback
impl PyTypeInfo for PyTraceback
Source§impl PyTypeInfo for PyTuple
impl PyTypeInfo for PyTuple
Source§impl PyTypeInfo for PyType
impl PyTypeInfo for PyType
Source§impl PyTypeInfo for PyTzInfo
Available on non-Py_LIMITED_API
only.
impl PyTypeInfo for PyTzInfo
Py_LIMITED_API
only.