pub unsafe trait PyTypeCheck {
const NAME: &'static str;
const TYPE_HINT: TypeHint;
// 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§
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.