Skip to content

PyPayload::class #[inline] #5846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions derive-impl/src/pypayload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {

let ret = quote! {
impl ::rustpython_vm::PyPayload for #ty {
#[inline]
fn class(_ctx: &::rustpython_vm::vm::Context) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
<Self as ::rustpython_vm::class::StaticType>::static_type()
}
Expand Down
4 changes: 4 additions & 0 deletions vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct PyAsyncGen {
type PyAsyncGenRef = PyRef<PyAsyncGen>;

impl PyPayload for PyAsyncGen {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.async_generator
}
Expand Down Expand Up @@ -141,6 +142,7 @@ impl Unconstructible for PyAsyncGen {}
#[derive(Debug)]
pub(crate) struct PyAsyncGenWrappedValue(pub PyObjectRef);
impl PyPayload for PyAsyncGenWrappedValue {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.async_generator_wrapped_value
}
Expand Down Expand Up @@ -190,6 +192,7 @@ pub(crate) struct PyAsyncGenASend {
}

impl PyPayload for PyAsyncGenASend {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.async_generator_asend
}
Expand Down Expand Up @@ -283,6 +286,7 @@ pub(crate) struct PyAsyncGenAThrow {
}

impl PyPayload for PyAsyncGenAThrow {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.async_generator_athrow
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl PyObjectRef {
pub struct PyBool;

impl PyPayload for PyBool {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.bool_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/bytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ pub struct PyByteArrayIterator {
}

impl PyPayload for PyByteArrayIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.bytearray_iterator_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl AsRef<[u8]> for PyBytesRef {
}

impl PyPayload for PyBytes {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.bytes_type
}
Expand Down Expand Up @@ -683,6 +684,7 @@ pub struct PyBytesIterator {
}

impl PyPayload for PyBytesIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.bytes_iterator_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/classmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl From<PyObjectRef> for PyClassMethod {
}

impl PyPayload for PyClassMethod {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.classmethod_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl fmt::Debug for PyCode {
}

impl PyPayload for PyCode {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.code_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl PyComplex {
}

impl PyPayload for PyComplex {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.complex_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct PyCoroutine {
}

impl PyPayload for PyCoroutine {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.coroutine_type
}
Expand Down Expand Up @@ -127,6 +128,7 @@ pub struct PyCoroutineWrapper {
}

impl PyPayload for PyCoroutineWrapper {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.coroutine_wrapper_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ macro_rules! dict_view {
}

impl PyPayload for $iter_name {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.$iter_class
}
Expand Down Expand Up @@ -896,6 +897,7 @@ macro_rules! dict_view {
}

impl PyPayload for $reverse_iter_name {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.$reverse_iter_class
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct PyEnumerate {
}

impl PyPayload for PyEnumerate {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.enumerate_type
}
Expand Down Expand Up @@ -92,6 +93,7 @@ pub struct PyReverseSequenceIterator {
}

impl PyPayload for PyReverseSequenceIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.reverse_iter_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct PyFilter {
}

impl PyPayload for PyFilter {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.filter_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl PyFloat {
}

impl PyPayload for PyFloat {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.float_type
}
Expand Down
3 changes: 3 additions & 0 deletions vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ impl PyFunction {
}

impl PyPayload for PyFunction {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.function_type
}
Expand Down Expand Up @@ -791,6 +792,7 @@ impl PyBoundMethod {
}

impl PyPayload for PyBoundMethod {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.bound_method_type
}
Expand Down Expand Up @@ -823,6 +825,7 @@ pub(crate) struct PyCell {
pub(crate) type PyCellRef = PyRef<PyCell>;

impl PyPayload for PyCell {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.cell_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct PyGenerator {
}

impl PyPayload for PyGenerator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.generator_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/genericalias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl fmt::Debug for PyGenericAlias {
}

impl PyPayload for PyGenericAlias {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.generic_alias_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/getset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl std::fmt::Debug for PyGetSet {
}

impl PyPayload for PyGetSet {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.getset_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ where
}

impl PyPayload for PyInt {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.int_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub struct PySequenceIterator {
}

impl PyPayload for PySequenceIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.iter_type
}
Expand Down Expand Up @@ -247,6 +248,7 @@ pub struct PyCallableIterator {
}

impl PyPayload for PyCallableIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.callable_iterator
}
Expand Down
3 changes: 3 additions & 0 deletions vm/src/builtins/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl FromIterator<PyObjectRef> for PyList {
}

impl PyPayload for PyList {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.list_type
}
Expand Down Expand Up @@ -538,6 +539,7 @@ pub struct PyListIterator {
}

impl PyPayload for PyListIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.list_iterator_type
}
Expand Down Expand Up @@ -583,6 +585,7 @@ pub struct PyListReverseIterator {
}

impl PyPayload for PyListReverseIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.list_reverseiterator_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct PyMap {
}

impl PyPayload for PyMap {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.map_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/mappingproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ unsafe impl Traverse for MappingProxyInner {
}

impl PyPayload for PyMappingProxy {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.mappingproxy_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ impl Hashable for PyMemoryView {
}

impl PyPayload for PyMemoryView {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.memoryview_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct PyModule {
}

impl PyPayload for PyModule {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.module_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
pub struct PyNamespace {}

impl PyPayload for PyNamespace {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.namespace_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use itertools::Itertools;
pub struct PyBaseObject;

impl PyPayload for PyBaseObject {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.object_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct PyProperty {
}

impl PyPayload for PyProperty {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.property_type
}
Expand Down
3 changes: 3 additions & 0 deletions vm/src/builtins/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct PyRange {
}

impl PyPayload for PyRange {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.range_type
}
Expand Down Expand Up @@ -533,6 +534,7 @@ pub struct PyLongRangeIterator {
}

impl PyPayload for PyLongRangeIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.long_range_iterator_type
}
Expand Down Expand Up @@ -598,6 +600,7 @@ pub struct PyRangeIterator {
}

impl PyPayload for PyRangeIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.range_iterator_type
}
Expand Down
3 changes: 3 additions & 0 deletions vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ impl fmt::Debug for PyFrozenSet {
}

impl PyPayload for PySet {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.set_type
}
}

impl PyPayload for PyFrozenSet {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.frozenset_type
}
Expand Down Expand Up @@ -1295,6 +1297,7 @@ impl fmt::Debug for PySetIterator {
}

impl PyPayload for PySetIterator {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.set_iterator_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/singletons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
pub struct PyNone;

impl PyPayload for PyNone {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.none_type
}
Expand Down Expand Up @@ -77,6 +78,7 @@ impl AsNumber for PyNone {
pub struct PyNotImplemented;

impl PyPayload for PyNotImplemented {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.not_implemented_type
}
Expand Down
2 changes: 2 additions & 0 deletions vm/src/builtins/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct PySlice {
}

impl PyPayload for PySlice {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.slice_type
}
Expand Down Expand Up @@ -302,6 +303,7 @@ impl Representable for PySlice {
pub struct PyEllipsis;

impl PyPayload for PyEllipsis {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.ellipsis_type
}
Expand Down
1 change: 1 addition & 0 deletions vm/src/builtins/staticmethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct PyStaticMethod {
}

impl PyPayload for PyStaticMethod {
#[inline]
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.staticmethod_type
}
Expand Down
Loading
Loading