Skip to main content

PyTypeCheck

Trait PyTypeCheck 

Source
pub unsafe trait PyTypeCheck {
    const TYPE_HINT: PyStaticExpr;

    // 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§

Source

const TYPE_HINT: PyStaticExpr

Available on crate feature experimental-inspect only.

Provides the full python type of the allowed values as a Python type hint.

Required Methods§

Source

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

Source

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".

Implementors§

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here