Skip to content

Commit 255a440

Browse files
committed
Drop struct sequence constructor_args option
Remove the constructor_args pystruct_sequence option, the PyStructSequence::CONSTRUCTOR_PARAMS constant, and their tests. The class signature of struct sequences again falls back to (iterable=(), /); sched_param keeps its #[pymethod] __reduce__. Assisted-by: Claude
1 parent 880ae1a commit 255a440

4 files changed

Lines changed: 4 additions & 92 deletions

File tree

‎crates/derive-impl/src/pyclass.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,9 +2744,7 @@ fn class_internal_doc(
27442744
quote! {
27452745
match #chosen {
27462746
Some(params) => Some(params),
2747-
None => ::rustpython_vm::function::real_signature(
2748-
<#payload as ::rustpython_vm::types::PyStructSequence>::CONSTRUCTOR_PARAMS,
2749-
),
2747+
None => ::rustpython_vm::types::STRUCT_SEQUENCE_PARAMS,
27502748
}
27512749
}
27522750
} else {

‎crates/derive-impl/src/pystructseq.rs‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ pub(crate) struct PyStructSequenceMeta {
386386
}
387387

388388
impl ItemMeta for PyStructSequenceMeta {
389-
const ALLOWED_NAMES: &'static [&'static str] =
390-
&["name", "module", "data", "no_attr", "constructor_args"];
389+
const ALLOWED_NAMES: &'static [&'static str] = &["name", "module", "data", "no_attr"];
391390

392391
fn from_inner(inner: ItemMetaInner) -> Self {
393392
Self { inner }
@@ -471,23 +470,13 @@ impl PyStructSequenceMeta {
471470
)
472471
}
473472

474-
fn constructor_args_type(&self) -> Result<Option<syn::Type>> {
475-
self.inner()
476-
._optional_str("constructor_args")?
477-
.map(|name| syn::parse_str(&name))
478-
.transpose()
479-
}
480-
481473
pub(crate) fn no_attr(&self) -> Result<bool> {
482474
self.inner()._bool("no_attr")
483475
}
484476
}
485477

486478
/// Attribute macro for struct sequences.
487479
///
488-
/// `constructor_args = "ArgsType"` connects the signature to the `FromArgs`
489-
/// type used by a custom `slot_new`. It does not change runtime construction.
490-
///
491480
/// Usage:
492481
/// ```ignore
493482
/// #[pystruct_sequence_data]
@@ -511,12 +500,6 @@ pub(crate) fn impl_pystruct_sequence(
511500
let pytype_ident = struct_item.ident.clone();
512501
let pytype_vis = struct_item.vis.clone();
513502
let data_ident = meta.data_type()?;
514-
let constructor_params = meta.constructor_args_type()?.map(|args| {
515-
quote! {
516-
const CONSTRUCTOR_PARAMS: Option<&'static [::rustpython_vm::function::Param]> =
517-
<#args as ::rustpython_vm::function::FromArgs>::PARAMS;
518-
}
519-
});
520503

521504
let class_name = meta.class_name()?.ok_or_else(|| {
522505
syn::Error::new_spanned(
@@ -628,7 +611,6 @@ pub(crate) fn impl_pystruct_sequence(
628611
// PyStructSequence trait for Python type
629612
impl ::rustpython_vm::types::PyStructSequence for #pytype_ident {
630613
type Data = #data_ident;
631-
#constructor_params
632614
}
633615

634616
// ToPyObject for Data struct - uses PyStructSequence::from_data

‎crates/vm/src/stdlib/posix.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,12 +3183,7 @@ mod posix_sched {
31833183
}
31843184

31853185
#[pyattr]
3186-
#[pystruct_sequence(
3187-
name = "sched_param",
3188-
module = "posix",
3189-
data = "SchedParamData",
3190-
constructor_args = "SchedParamArgs"
3191-
)]
3186+
#[pystruct_sequence(name = "sched_param", module = "posix", data = "SchedParamData")]
31923187
struct PySchedParam;
31933188

31943189
#[pyclass(with(PyStructSequence))]

‎crates/vm/src/types/structseq.rs‎

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const DEFAULT_STRUCTSEQ_REDUCE: PyMethodDef = PyMethodDef::new_const(
2828
crate::function::ItemDoc::static_text("__reduce__($self, /)\n--\n\n"),
2929
);
3030

31-
/// Default text signature `(iterable=(), /)` for struct sequences.
31+
/// Text signature `(iterable=(), /)` shared by every struct sequence.
3232
pub const STRUCT_SEQUENCE_PARAMS: Option<&'static [crate::function::Param]> =
3333
Some(&[crate::function::Param {
3434
name: "iterable",
@@ -261,10 +261,6 @@ pub trait PyStructSequence: StaticType + PyClassImpl + Sized + 'static {
261261
/// The Data struct that provides field definitions.
262262
type Data: PyStructSequenceData;
263263

264-
/// Signature metadata for the constructor, including custom `slot_new` binders.
265-
/// This does not change the constructor slot or tuple payload.
266-
const CONSTRUCTOR_PARAMS: Option<&'static [crate::function::Param]> = STRUCT_SEQUENCE_PARAMS;
267-
268264
#[pyslot]
269265
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
270266
struct_sequence_new(
@@ -532,62 +528,3 @@ fn struct_sequence_richcompare(
532528
.map(|o| &**o)
533529
.richcompare(other_visible.iter().map(|o| &**o), op, vm)
534530
}
535-
536-
#[cfg(test)]
537-
mod signature_metadata_tests {
538-
use super::PyStructSequence;
539-
use crate::{PyObjectRef, class::PyClassImpl};
540-
541-
#[pystruct_sequence_data]
542-
struct DefaultData {
543-
value: PyObjectRef,
544-
}
545-
546-
#[pystruct_sequence(name = "metadata_default", data = "DefaultData")]
547-
struct MetadataDefault;
548-
549-
#[pyclass(with(PyStructSequence))]
550-
impl MetadataDefault {}
551-
552-
#[allow(dead_code)]
553-
#[derive(FromArgs)]
554-
struct CustomArgs {
555-
#[pyarg(any)]
556-
value: PyObjectRef,
557-
}
558-
559-
#[pystruct_sequence_data]
560-
struct CustomData {
561-
value: PyObjectRef,
562-
}
563-
564-
#[pystruct_sequence(
565-
name = "metadata_custom",
566-
data = "CustomData",
567-
constructor_args = "CustomArgs"
568-
)]
569-
struct MetadataCustom;
570-
571-
#[pyclass(with(PyStructSequence))]
572-
impl MetadataCustom {}
573-
574-
#[test]
575-
fn ordinary_struct_sequence_signature_keeps_its_fallback() {
576-
assert!(
577-
MetadataDefault::INTERNAL_DOC
578-
.text
579-
.unwrap()
580-
.starts_with("metadata_default(iterable=(), /)\n--\n\n")
581-
);
582-
}
583-
584-
#[test]
585-
fn custom_constructor_args_signature_uses_fromargs_params() {
586-
assert!(
587-
MetadataCustom::INTERNAL_DOC
588-
.text
589-
.unwrap()
590-
.starts_with("metadata_custom(value)\n--\n\n")
591-
);
592-
}
593-
}

0 commit comments

Comments
 (0)