every PyStructSequence is StaticType · RustPython/RustPython@57bf7af · GitHub
Skip to content

Commit 57bf7af

Browse files
committed
every PyStructSequence is StaticType
1 parent 3b78c60 commit 57bf7af

6 files changed

Lines changed: 30 additions & 50 deletions

File tree

vm/src/pyobject.rs

Lines changed: 4 additions & 3 deletions

vm/src/stdlib/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ mod _io {
730730
size: OptionalOption<PyObjectRef>,
731731
vm: &VirtualMachine,
732732
) -> PyResult<String> {
733-
let buffered_reader_class = vm.try_class("_io", "BufferedReader")?;
733+
let buffered_reader_class = BufferedReader::static_type();
734734
let raw = vm.get_attribute(instance, "buffer").unwrap();
735735

736736
if !raw.isinstance(&buffered_reader_class) {
@@ -754,7 +754,7 @@ mod _io {
754754
fn write(instance: PyObjectRef, obj: PyStrRef, vm: &VirtualMachine) -> PyResult<usize> {
755755
use std::str::from_utf8;
756756

757-
let buffered_writer_class = vm.try_class("_io", "BufferedWriter")?;
757+
let buffered_writer_class = BufferedWriter::static_type();
758758
let raw = vm.get_attribute(instance, "buffer").unwrap();
759759

760760
if !raw.isinstance(&buffered_writer_class) {
@@ -781,7 +781,7 @@ mod _io {
781781
size: OptionalOption<PyObjectRef>,
782782
vm: &VirtualMachine,
783783
) -> PyResult<String> {
784-
let buffered_reader_class = vm.try_class("_io", "BufferedReader")?;
784+
let buffered_reader_class = BufferedReader::static_type();
785785
let raw = vm.get_attribute(instance, "buffer").unwrap();
786786

787787
if !raw.isinstance(&buffered_reader_class) {

vm/src/stdlib/os.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,7 @@ mod _os {
636636
#[pyimpl(with(PyStructSequence))]
637637
impl StatResult {
638638
pub(super) fn into_obj(self, vm: &VirtualMachine) -> PyObjectRef {
639-
self.into_struct_sequence(vm, StatResult::static_type().clone())
640-
.unwrap()
641-
.into_object()
639+
self.into_struct_sequence(vm).unwrap().into_object()
642640
}
643641
}
644642

@@ -1745,9 +1743,7 @@ mod posix {
17451743
#[pyimpl(with(PyStructSequence))]
17461744
impl UnameResult {
17471745
fn into_obj(self, vm: &VirtualMachine) -> PyObjectRef {
1748-
self.into_struct_sequence(vm, UnameResult::static_type().clone())
1749-
.unwrap()
1750-
.into_object()
1746+
self.into_struct_sequence(vm).unwrap().into_object()
17511747
}
17521748
}
17531749

@@ -2143,8 +2139,7 @@ mod posix {
21432139
(w.ws_col.into(), w.ws_row.into())
21442140
}
21452141
};
2146-
super::_os::PyTerminalSize { columns, lines }
2147-
.into_struct_sequence(vm, vm.try_class(super::MODULE_NAME, "terminal_size")?)
2142+
super::_os::PyTerminalSize { columns, lines }.into_struct_sequence(vm)
21482143
}
21492144

21502145
// from libstd:
@@ -2466,8 +2461,7 @@ mod nt {
24662461
)
24672462
}
24682463
};
2469-
super::_os::PyTerminalSize { columns, lines }
2470-
.into_struct_sequence(vm, vm.try_class(super::MODULE_NAME, "terminal_size")?)
2464+
super::_os::PyTerminalSize { columns, lines }.into_struct_sequence(vm)
24712465
}
24722466

24732467
#[cfg(target_env = "msvc")]

vm/src/stdlib/pwd.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl From<User> for Passwd {
4848

4949
fn pwd_getpwnam(name: PyStrRef, vm: &VirtualMachine) -> PyResult {
5050
match User::from_name(name.borrow_value()).map_err(|err| err.into_pyexception(vm))? {
51-
Some(user) => Ok(Passwd::from(user)
52-
.into_struct_sequence(vm, vm.try_class("pwd", "struct_passwd")?)?
53-
.into_object()),
51+
Some(user) => Ok(Passwd::from(user).into_struct_sequence(vm)?.into_object()),
5452
None => {
5553
let name_repr = vm.to_repr(name.as_object())?;
5654
let message = vm
@@ -68,9 +66,7 @@ fn pwd_getpwuid(uid: PyIntRef, vm: &VirtualMachine) -> PyResult {
6866
Err(_) => None,
6967
};
7068
match user {
71-
Some(user) => Ok(Passwd::from(user)
72-
.into_struct_sequence(vm, vm.try_class("pwd", "struct_passwd")?)?
73-
.into_object()),
69+
Some(user) => Ok(Passwd::from(user).into_struct_sequence(vm)?.into_object()),
7470
None => {
7571
let message = vm
7672
.ctx
@@ -86,14 +82,11 @@ fn pwd_getpwall(vm: &VirtualMachine) -> PyResult {
8682
static GETPWALL: parking_lot::Mutex<()> = parking_lot::const_mutex(());
8783
let _guard = GETPWALL.lock();
8884
let mut list = Vec::new();
89-
let cls = vm.try_class("pwd", "struct_passwd")?;
9085

9186
unsafe { libc::setpwent() };
9287
while let Some(ptr) = NonNull::new(unsafe { libc::getpwent() }) {
9388
let user = User::from(unsafe { ptr.as_ref() });
94-
let passwd = Passwd::from(user)
95-
.into_struct_sequence(vm, cls.clone())?
96-
.into_object();
89+
let passwd = Passwd::from(user).into_struct_sequence(vm)?.into_object();
9790
list.push(passwd);
9891
}
9992
unsafe { libc::endpwent() };

vm/src/stdlib/time_module.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use crate::builtins::pytype::PyTypeRef;
1212
use crate::builtins::tuple::PyTupleRef;
1313
use crate::function::OptionalArg;
1414
use crate::pyobject::{
15-
BorrowValue, Either, PyClassImpl, PyObjectRef, PyResult, PyStructSequence, StaticType,
16-
TryFromObject,
15+
BorrowValue, Either, PyClassImpl, PyObjectRef, PyResult, PyStructSequence, TryFromObject,
1716
};
1817
use crate::vm::VirtualMachine;
1918

@@ -219,14 +218,13 @@ impl PyStructTime {
219218
}
220219

221220
fn into_obj(self, vm: &VirtualMachine) -> PyObjectRef {
222-
self.into_struct_sequence(vm, PyStructTime::static_type().clone())
223-
.unwrap()
224-
.into_object()
221+
self.into_struct_sequence(vm).unwrap().into_object()
225222
}
226223

227224
#[pyslot]
228-
fn tp_new(cls: PyTypeRef, seq: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
229-
Self::try_from_object(vm, seq)?.into_struct_sequence(vm, cls)
225+
fn tp_new(_cls: PyTypeRef, seq: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyTupleRef> {
226+
// cls is ignorable because this is not a basetype
227+
Self::try_from_object(vm, seq)?.into_struct_sequence(vm)
230228
}
231229
}
232230

vm/src/sysmodule.rs

Lines changed: 11 additions & 17 deletions

0 commit comments

Comments
 (0)