Skip to content

Commit 0948971

Browse files
committed
PyPayload::payload_type_of
1 parent 635b4af commit 0948971

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

vm/src/object/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl PyObject {
655655

656656
#[inline(always)]
657657
pub fn payload_is<T: PyObjectPayload>(&self) -> bool {
658-
self.0.typeid == TypeId::of::<T>()
658+
self.0.typeid == T::payload_type_id()
659659
}
660660

661661
/// Force to return payload as T.

vm/src/object/payload.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ cfg_if::cfg_if! {
1919
pub trait PyPayload:
2020
std::fmt::Debug + MaybeTraverse + PyThreadingConstraint + Sized + 'static
2121
{
22+
#[inline]
23+
fn payload_type_id() -> std::any::TypeId {
24+
std::any::TypeId::of::<Self>()
25+
}
2226
fn class(ctx: &Context) -> &'static Py<PyType>;
2327

2428
#[inline]
@@ -75,7 +79,7 @@ pub trait PyPayload:
7579
}
7680

7781
pub trait PyObjectPayload:
78-
std::any::Any + std::fmt::Debug + MaybeTraverse + PyThreadingConstraint + 'static
82+
PyPayload + std::any::Any + std::fmt::Debug + MaybeTraverse + PyThreadingConstraint + 'static
7983
{
8084
}
8185

0 commit comments

Comments
 (0)