@@ -15,7 +15,6 @@ use super::{
1515 ext:: { AsObject , PyRefExact , PyResult } ,
1616 payload:: PyPayload ,
1717} ;
18- use crate :: object:: traverse_object:: PyObjVTable ;
1918use crate :: {
2019 builtins:: { PyDictRef , PyType , PyTypeRef } ,
2120 common:: {
@@ -24,6 +23,7 @@ use crate::{
2423 lock:: { PyMutex , PyMutexGuard , PyRwLock } ,
2524 refcount:: RefCount ,
2625 } ,
26+ object:: { PyObjectPayload , traverse_object:: PyObjVTable } ,
2727 vm:: VirtualMachine ,
2828} ;
2929use crate :: {
@@ -105,8 +105,6 @@ pub(super) unsafe fn try_trace_obj<T: PyPayload>(x: &PyObject, tracer_fn: &mut T
105105#[ repr( C ) ]
106106pub ( super ) struct PyInner < T > {
107107 pub ( super ) ref_count : RefCount ,
108- // TODO: move typeid into vtable once TypeId::of is const
109- pub ( super ) typeid : TypeId ,
110108 pub ( super ) vtable : & ' static PyObjVTable ,
111109
112110 pub ( super ) typ : PyAtomicRef < PyType > , // __class__ member
@@ -449,7 +447,6 @@ impl<T: PyPayload + core::fmt::Debug> PyInner<T> {
449447 let member_count = typ. slots . member_count ;
450448 Box :: new ( Self {
451449 ref_count : RefCount :: new ( ) ,
452- typeid : T :: payload_type_id ( ) ,
453450 vtable : PyObjVTable :: of :: < T > ( ) ,
454451 typ : PyAtomicRef :: from ( typ) ,
455452 dict : dict. map ( InstanceDict :: new) ,
@@ -638,8 +635,8 @@ impl PyObject {
638635
639636 #[ deprecated( note = "use downcastable instead" ) ]
640637 #[ inline( always) ]
641- pub fn payload_is < T : PyPayload > ( & self ) -> bool {
642- self . 0 . typeid == T :: payload_type_id ( )
638+ pub fn payload_is < T : PyObjectPayload > ( & self ) -> bool {
639+ self . 0 . vtable . typeid == T :: PAYLOAD_TYPE_ID
643640 }
644641
645642 /// Force to return payload as T.
@@ -657,7 +654,7 @@ impl PyObject {
657654
658655 #[ deprecated( note = "use downcast_ref instead" ) ]
659656 #[ inline( always) ]
660- pub fn payload < T : PyPayload > ( & self ) -> Option < & T > {
657+ pub fn payload < T : PyPayload + std :: fmt :: Debug > ( & self ) -> Option < & T > {
661658 #[ allow( deprecated) ]
662659 if self . payload_is :: < T > ( ) {
663660 #[ allow( deprecated) ]
@@ -678,7 +675,10 @@ impl PyObject {
678675
679676 #[ deprecated( note = "use downcast_ref_if_exact instead" ) ]
680677 #[ inline( always) ]
681- pub fn payload_if_exact < T : PyPayload > ( & self , vm : & VirtualMachine ) -> Option < & T > {
678+ pub fn payload_if_exact < T : PyPayload + std:: fmt:: Debug > (
679+ & self ,
680+ vm : & VirtualMachine ,
681+ ) -> Option < & T > {
682682 if self . class ( ) . is ( T :: class ( & vm. ctx ) ) {
683683 #[ allow( deprecated) ]
684684 self . payload ( )
@@ -711,7 +711,10 @@ impl PyObject {
711711
712712 #[ deprecated( note = "use downcast_ref instead" ) ]
713713 #[ inline( always) ]
714- pub fn payload_if_subclass < T : crate :: PyPayload > ( & self , vm : & VirtualMachine ) -> Option < & T > {
714+ pub fn payload_if_subclass < T : crate :: PyPayload + std:: fmt:: Debug > (
715+ & self ,
716+ vm : & VirtualMachine ,
717+ ) -> Option < & T > {
715718 if self . class ( ) . fast_issubclass ( T :: class ( & vm. ctx ) ) {
716719 #[ allow( deprecated) ]
717720 self . payload ( )
@@ -722,7 +725,7 @@ impl PyObject {
722725
723726 #[ inline]
724727 pub ( crate ) fn typeid ( & self ) -> TypeId {
725- self . 0 . typeid
728+ self . 0 . vtable . typeid
726729 }
727730
728731 /// Check if this object can be downcast to T.
@@ -1276,7 +1279,6 @@ pub(crate) fn init_type_hierarchy() -> (PyTypeRef, PyTypeRef, PyTypeRef) {
12761279 let type_type_ptr = Box :: into_raw ( Box :: new ( partially_init ! (
12771280 PyInner :: <PyType > {
12781281 ref_count: RefCount :: new( ) ,
1279- typeid: TypeId :: of:: <PyType >( ) ,
12801282 vtable: PyObjVTable :: of:: <PyType >( ) ,
12811283 dict: None ,
12821284 weak_list: WeakRefList :: new( ) ,
@@ -1288,7 +1290,6 @@ pub(crate) fn init_type_hierarchy() -> (PyTypeRef, PyTypeRef, PyTypeRef) {
12881290 let object_type_ptr = Box :: into_raw ( Box :: new ( partially_init ! (
12891291 PyInner :: <PyType > {
12901292 ref_count: RefCount :: new( ) ,
1291- typeid: TypeId :: of:: <PyType >( ) ,
12921293 vtable: PyObjVTable :: of:: <PyType >( ) ,
12931294 dict: None ,
12941295 weak_list: WeakRefList :: new( ) ,
0 commit comments