Skip to content

Commit 799541b

Browse files
Merge pull request RustPython#1619 from RustPython/coolreader18/time-structseq
Make time.struct_time a struct_sequence
2 parents 124dbfb + 68e9c12 commit 799541b

File tree

4 files changed

+99
-229
lines changed

4 files changed

+99
-229
lines changed

derive/src/pyclass.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,12 @@ pub fn impl_pystruct_sequence(attr: AttributeArgs, item: Item) -> Result<TokenSt
439439
let property = quote! {
440440
class.set_str_attr(
441441
#field_name_str,
442-
::rustpython_vm::obj::objproperty::PropertyBuilder::new(ctx)
443-
.add_getter(|zelf: &::rustpython_vm::obj::objtuple::PyTuple,
444-
_vm: &::rustpython_vm::vm::VirtualMachine|
445-
zelf.fast_getitem(#idx))
446-
.create(),
442+
ctx.new_property(
443+
|zelf: &::rustpython_vm::obj::objtuple::PyTuple,
444+
_vm: &::rustpython_vm::VirtualMachine| {
445+
zelf.fast_getitem(#idx)
446+
}
447+
),
447448
);
448449
};
449450
properties.push(property);
@@ -459,7 +460,7 @@ pub fn impl_pystruct_sequence(attr: AttributeArgs, item: Item) -> Result<TokenSt
459460
#class_def
460461
impl #ty {
461462
pub fn into_struct_sequence(&self,
462-
vm: &::rustpython_vm::vm::VirtualMachine,
463+
vm: &::rustpython_vm::VirtualMachine,
463464
cls: ::rustpython_vm::obj::objtype::PyClassRef,
464465
) -> ::rustpython_vm::pyobject::PyResult<::rustpython_vm::obj::objtuple::PyTupleRef> {
465466
let tuple = ::rustpython_vm::obj::objtuple::PyTuple::from(

vm/src/obj/objiter.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ impl PySequenceIterator {
127127
}
128128
}
129129

130+
pub fn seq_iter_method(obj: PyObjectRef, _vm: &VirtualMachine) -> PySequenceIterator {
131+
PySequenceIterator {
132+
position: Cell::new(0),
133+
obj,
134+
reversed: false,
135+
}
136+
}
137+
130138
pub fn init(context: &PyContext) {
131139
PySequenceIterator::extend_class(context, &context.types.iter_type);
132140
}

0 commit comments

Comments
 (0)