pub struct PyType {
pub base: Option<PyTypeRef>,
pub bases: PyRwLock<Vec<PyTypeRef>>,
pub mro: PyRwLock<Vec<PyTypeRef>>,
pub subclasses: PyRwLock<Vec<PyRef<PyWeak>>>,
pub attributes: PyRwLock<IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>>,
pub slots: PyTypeSlots,
pub heaptype_ext: Option<Pin<Box<HeapTypeExt>>>,
pub tp_version_tag: AtomicU32,
}Fields§
§base: Option<PyTypeRef>§bases: PyRwLock<Vec<PyTypeRef>>§mro: PyRwLock<Vec<PyTypeRef>>§subclasses: PyRwLock<Vec<PyRef<PyWeak>>>§attributes: PyRwLock<IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>>§slots: PyTypeSlots§heaptype_ext: Option<Pin<Box<HeapTypeExt>>>§tp_version_tag: AtomicU32Type version tag for inline caching. 0 means unassigned/invalidated.
Implementations§
Source§impl PyType
impl PyType
Sourcepub fn assign_version_tag(&self) -> u32
pub fn assign_version_tag(&self) -> u32
Assign a fresh version tag. Returns 0 if the version counter has been exhausted, in which case no new cache entries can be created.
pub fn new_simple_heap( name: &str, base: &Py<PyType>, ctx: &Context, ) -> Result<PyRef<Self>, String>
pub fn new_heap( name: &str, bases: Vec<PyRef<Self>>, attrs: IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>, slots: PyTypeSlots, metaclass: PyRef<Self>, ctx: &Context, ) -> Result<PyRef<Self>, String>
pub fn new_static( base: PyRef<Self>, attrs: IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>, slots: PyTypeSlots, metaclass: PyRef<Self>, ) -> Result<PyRef<Self>, String>
pub fn set_str_attr<V: Into<PyObjectRef>>( &self, attr_name: &str, value: V, ctx: impl AsRef<Context>, )
pub fn set_attr(&self, attr_name: &'static PyStrInterned, value: PyObjectRef)
Sourcepub fn get_attr(&self, attr_name: &'static PyStrInterned) -> Option<PyObjectRef>
pub fn get_attr(&self, attr_name: &'static PyStrInterned) -> Option<PyObjectRef>
Internal get_attr implementation for fast lookup on a class. Searches the full MRO (including self) with method cache acceleration.
pub fn get_direct_attr( &self, attr_name: &'static PyStrInterned, ) -> Option<PyObjectRef>
Sourcepub fn lookup_ref(
&self,
name: &Py<PyStr>,
vm: &VirtualMachine,
) -> Option<PyObjectRef>
pub fn lookup_ref( &self, name: &Py<PyStr>, vm: &VirtualMachine, ) -> Option<PyObjectRef>
_PyType_LookupRef: look up a name through the MRO without setting an exception.
pub fn get_super_attr( &self, attr_name: &'static PyStrInterned, ) -> Option<PyObjectRef>
Sourcepub fn has_attr(&self, attr_name: &'static PyStrInterned) -> bool
pub fn has_attr(&self, attr_name: &'static PyStrInterned) -> bool
Fast lookup for attribute existence on a class.
pub fn get_attributes( &self, ) -> IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>
pub fn slot_name(&self) -> BorrowedValue<'_, str>
pub fn name(&self) -> BorrowedValue<'_, str>
Sourcepub fn init_type_data<T: Any + Send + Sync + 'static>(
&self,
data: T,
) -> Result<(), String>
pub fn init_type_data<T: Any + Send + Sync + 'static>( &self, data: T, ) -> Result<(), String>
Initialize type data for this type. Can only be called once. Returns an error if the type is not a heap type or if data is already initialized.
Sourcepub fn get_type_data<T: Any + 'static>(&self) -> Option<TypeDataRef<'_, T>>
pub fn get_type_data<T: Any + 'static>(&self) -> Option<TypeDataRef<'_, T>>
Get a read guard to the type data. Returns None if the type is not a heap type, has no data, or the data type doesn’t match.
Sourcepub fn get_type_data_mut<T: Any + 'static>(
&self,
) -> Option<TypeDataRefMut<'_, T>>
pub fn get_type_data_mut<T: Any + 'static>( &self, ) -> Option<TypeDataRefMut<'_, T>>
Get a write guard to the type data. Returns None if the type is not a heap type, has no data, or the data type doesn’t match.
Sourcepub fn has_type_data<T: Any + 'static>(&self) -> bool
pub fn has_type_data<T: Any + 'static>(&self) -> bool
Check if this type has type data of the given type.
Source§impl PyType
impl PyType
pub fn __name__(&self, vm: &VirtualMachine) -> PyStrRef
pub fn __qualname__(&self, vm: &VirtualMachine) -> PyObjectRef
pub fn __module__(&self, vm: &VirtualMachine) -> PyObjectRef
pub fn __ror__( zelf: PyObjectRef, other: PyObjectRef, vm: &VirtualMachine, ) -> PyResult
pub fn __or__( zelf: PyObjectRef, other: PyObjectRef, vm: &VirtualMachine, ) -> PyResult
Trait Implementations§
Source§impl AsNumber for PyType
impl AsNumber for PyType
fn as_number() -> &'static PyNumberMethods
fn extend_slots(slots: &mut PyTypeSlots)
fn clone_exact(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyRef<Self>
fn number_downcast(num: PyNumber<'_>) -> &Py<Self>
fn number_downcast_exact(num: PyNumber<'_>, vm: &VirtualMachine) -> PyRef<Self>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl Callable for PyType
impl Callable for PyType
type Args = FuncArgs
fn call(zelf: &Py<Self>, args: FuncArgs, vm: &VirtualMachine) -> PyResult
fn slot_call(zelf: &PyObject, args: FuncArgs, vm: &VirtualMachine) -> PyResult
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl Constructor for PyType
impl Constructor for PyType
type Args = FuncArgs
Source§fn slot_new(
metatype: PyTypeRef,
args: FuncArgs,
vm: &VirtualMachine,
) -> PyResult
fn slot_new( metatype: PyTypeRef, args: FuncArgs, vm: &VirtualMachine, ) -> PyResult
__new__. Override this only when you need special
behavior beyond simple payload creation.Source§fn py_new(
_cls: &Py<PyType>,
_args: Self::Args,
_vm: &VirtualMachine,
) -> PyResult<Self>
fn py_new( _cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine, ) -> PyResult<Self>
slot_new handle wrapping with the correct type.const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl GetAttr for PyType
impl GetAttr for PyType
fn getattro( zelf: &Py<Self>, name_str: &Py<PyStr>, vm: &VirtualMachine, ) -> PyResult
fn slot_getattro( obj: &PyObject, name: &Py<PyStr>, vm: &VirtualMachine, ) -> PyResult
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl Initializer for PyType
impl Initializer for PyType
type Args = FuncArgs
fn slot_init( _zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine, ) -> PyResult<()>
fn init( _zelf: PyRef<Self>, _args: Self::Args, _vm: &VirtualMachine, ) -> PyResult<()>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl MaybeTraverse for PyType
impl MaybeTraverse for PyType
Source§const HAS_TRAVERSE: bool = true
const HAS_TRAVERSE: bool = true
Source§const HAS_CLEAR: bool = true
const HAS_CLEAR: bool = true
fn try_traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn try_clear(&mut self, out: &mut Vec<PyObjectRef>)
Source§impl PyClassDef for PyType
impl PyClassDef for PyType
const NAME: &'static str = "type"
const MODULE_NAME: Option<&'static str> = None
const TP_NAME: &'static str = "type"
const DOC: Option<&'static str>
const BASICSIZE: usize
const UNHASHABLE: bool = false
type Base = PyBaseObject
const ITEMSIZE: usize = 0
Source§impl PyClassImpl for PyType
impl PyClassImpl for PyType
const TP_FLAGS: PyTypeFlags
const METHOD_DEFS: &'static [PyMethodDef]
fn impl_extend_class(ctx: &'static Context, class: &'static Py<PyType>)
fn extend_slots(slots: &mut PyTypeSlots)
fn extend_class(ctx: &'static Context, class: &'static Py<PyType>)where
Self: Sized,
fn make_static_type() -> PyTypeRefwhere
Self: StaticType + Sized,
fn make_slots() -> PyTypeSlots
Source§impl PyPayload for PyType
impl PyPayload for PyType
fn class(ctx: &Context) -> &'static Py<PyType>
const PAYLOAD_TYPE_ID: TypeId = _
fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()>
Source§const HAS_FREELIST: bool = false
const HAS_FREELIST: bool = false
Source§const MAX_FREELIST: usize = 0
const MAX_FREELIST: usize = 0
Source§unsafe fn freelist_push(_obj: *mut PyObject) -> bool
unsafe fn freelist_push(_obj: *mut PyObject) -> bool
Source§unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
ref_count, gc_bits, and payload. Read morefn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRefwhere
Self: Debug,
fn _into_ref(self, cls: PyTypeRef, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_exact_ref(self, ctx: &Context) -> PyRefExact<Self>where
Self: Debug,
fn into_ref(self, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_ref_with_type(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
Source§impl Representable for PyType
impl Representable for PyType
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String>
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>>
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>>
fn repr_wtf8(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<Wtf8Buf>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl SetAttr for PyType
impl SetAttr for PyType
fn setattro( zelf: &Py<Self>, attr_name: &Py<PyStr>, value: PySetterValue, vm: &VirtualMachine, ) -> PyResult<()>
fn slot_setattro( obj: &PyObject, name: &Py<PyStr>, value: PySetterValue, vm: &VirtualMachine, ) -> PyResult<()>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl StaticType for PyType
impl StaticType for PyType
fn static_cell() -> &'static StaticCell<PyTypeRef>
fn static_metaclass() -> &'static Py<PyType>
fn static_baseclass() -> &'static Py<PyType>
fn static_type() -> &'static Py<PyType>
fn init_manually(typ: PyTypeRef) -> &'static Py<PyType>
fn init_builtin_type() -> &'static Py<PyType>where
Self: PyClassImpl,
fn create_static_type() -> PyTypeRefwhere
Self: PyClassImpl,
Auto Trait Implementations§
impl !Freeze for PyType
impl !RefUnwindSafe for PyType
impl !Send for PyType
impl !Sync for PyType
impl Unpin for PyType
impl UnsafeUnpin for PyType
impl !UnwindSafe for PyType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
Source§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
Source§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more