pub struct PyType {
pub base: PyAtomicRef<Option<Self>>,
pub bases: PyRwLock<PyRef<PyTuple<PyTypeRef>>>,
pub mro: PyRwLock<Vec<PyTypeRef>>,
pub subclasses: PyRwLock<Vec<PyRef<PyWeak>>>,
pub attributes: TypeNamespace,
pub slots: PyTypeSlots,
pub heaptype_ext: Option<Pin<Box<HeapTypeExt>>>,
pub tp_version_tag: AtomicU32,
}Fields§
§base: PyAtomicRef<Option<Self>>§bases: PyRwLock<PyRef<PyTuple<PyTypeRef>>>§mro: PyRwLock<Vec<PyTypeRef>>§subclasses: PyRwLock<Vec<PyRef<PyWeak>>>§attributes: TypeNamespace§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
pub fn modified(&self)
Sourcepub fn is_visible_to_interpreter(&self, interpreter_id: i64) -> bool
pub fn is_visible_to_interpreter(&self, interpreter_id: i64) -> bool
Whether the interpreter with interpreter_id can see this type.
Interpreters share the context, so a subclass of a shared type is recorded on an object every interpreter reaches. Only the interpreter that created it can name it, so only that one lists it.
pub fn new_simple_heap( name: &str, base: &Py<Self>, 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 has_patma_collection_flag(&self, flag: u8) -> bool
pub fn set_is_abstract(&self, is_abstract: bool)
pub fn set_abc_collection_flags_recursive(&self, flags: PyTypeFlags)
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, ctx: &Context, ) -> IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>
pub fn slot_name(&self) -> BorrowedValue<'_, str>
pub fn __qualname__(&self, vm: &VirtualMachine) -> PyObjectRef
pub fn __module__(&self, vm: &VirtualMachine) -> PyResult<PyObjectRef>
Sourcepub fn fully_qualified_name(&self, vm: &VirtualMachine) -> PyResult<String>
pub fn fully_qualified_name(&self, vm: &VirtualMachine) -> PyResult<String>
The type’s fully qualified name, the way the %T format code prints it:
module.qualname, with a builtins or __main__ module left off.
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 __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.Source§const DROP_KWARGS_WHEN_INIT_OVERRIDDEN: bool = false
const DROP_KWARGS_WHEN_INIT_OVERRIDDEN: bool = false
tp_init.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: &PyObject, args: FuncArgs, vm: &VirtualMachine, ) -> PyResult<()>
fn init( _zelf: &Py<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: ItemDoc
Source§const ATTR_DOCS: &'static [(&'static str, u32, u32)]
const ATTR_DOCS: &'static [(&'static str, u32, u32)]
(u32::MAX, 0) is an explicit empty doc.const BASICSIZE: usize
const UNHASHABLE: bool = false
const MEMBERS: &'static [PyMemberSpec]
type Base = PyBaseObject
fn assert_member_layout()
const ITEMSIZE: usize = 0
Source§impl PyClassImpl for PyType
impl PyClassImpl for PyType
const TP_FLAGS: PyTypeFlags
Source§const INTERNAL_DOC: ItemDoc
const INTERNAL_DOC: ItemDoc
ItemDoc::NONE when the constructor has no signature.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 NEW_REF_UNTRACKED: bool = false
const NEW_REF_UNTRACKED: bool = false
PyRef::new_ref skips auto-tracking this type in the GC even
when it would otherwise qualify (has traverse, dict, or heap type).
Such objects are created untracked and must be tracked explicitly if
and when they can become part of a reference cycle. Used by FrameObject,
which is created untracked and tracked lazily only on escape.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§fn into_ref_with_type_lazy_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
fn into_ref_with_type_lazy_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
into_ref_with_type, but leaves the instance __dict__ unallocated
until the first attribute write or __dict__ access. Only valid for types
whose attribute protocol materializes the dict lazily via get_or_insert.fn into_ref_with_type_and_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
eager_dict: bool,
) -> 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 !UnwindSafe for PyType
impl Unpin for PyType
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Helper for T
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
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)
impl<T> PrimitiveIntRandomBounds for T
impl<T> PrimitiveSignedRandomBounds for T
impl<T> PyObjectPayload for T
impl<T> PyThreadingConstraint for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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> ToCharString for Twhere
T: Display,
impl<T> ToCharString for Twhere
T: Display,
Source§fn try_to_char_string(&self) -> Result<CharString, ToCharStringError>
fn try_to_char_string(&self) -> Result<CharString, ToCharStringError>
CharString. Read moreSource§fn to_char_string(&self) -> CharString
fn to_char_string(&self) -> CharString
CharString. Read moreSource§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