pub unsafe trait PyTypeCheck {
const NAME: &'static str;
const PYTHON_TYPE: &'static str;
// Required methods
fn type_check(object: &Bound<'_, PyAny>) -> bool;
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>;
}Expand description
Implemented by types which can be used as a concrete Python type inside Py<T> smart pointers.
§Safety
This trait is used to determine whether Bound::cast and similar functions can safely cast
to a concrete type. The implementor is responsible for ensuring that type_check only returns
true for objects which can safely be treated as Python instances of Self.
Required Associated Constants§
Sourceconst NAME: &'static str
👎Deprecated since 0.27.0: Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
const NAME: &'static str
Name of self. This is used in error messages, for example.
Sourceconst PYTHON_TYPE: &'static str
Available on crate feature experimental-inspect only.
const PYTHON_TYPE: &'static str
experimental-inspect only.Provides the full python type of the allowed values.
Required Methods§
Sourcefn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
Checks if object is an instance of Self, which may include a subtype.
This should be equivalent to the Python expression isinstance(object, Self).
Sourcefn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
Returns the expected type as a possible argument for the isinstance and issubclass function.
It may be a single type or a tuple of types.
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.