Skip to content

Commit f6d70c8

Browse files
committed
Into{PyObject,PyException,Pyresult} -> To{..}
The naming convention was wrong
1 parent 0f4b3ec commit f6d70c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+569
-594
lines changed

derive/src/pystructseq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ pub(crate) fn impl_pystruct_sequence(input: DeriveInput) -> Result<TokenStream>
2929
impl ::rustpython_vm::PyStructSequence for #ty {
3030
const FIELD_NAMES: &'static [&'static str] = &[#(stringify!(#field_names)),*];
3131
fn into_tuple(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::builtins::PyTuple {
32-
let items = vec![#(::rustpython_vm::function::IntoPyObject::into_pyobject(
32+
let items = vec![#(::rustpython_vm::function::ToPyObject::to_pyobject(
3333
self.#field_names,
3434
vm,
3535
)),*];
3636
::rustpython_vm::builtins::PyTuple::new_unchecked(items.into_boxed_slice())
3737
}
3838
}
39-
impl ::rustpython_vm::function::IntoPyObject for #ty {
40-
fn into_pyobject(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::PyObjectRef {
39+
impl ::rustpython_vm::function::ToPyObject for #ty {
40+
fn to_pyobject(self, vm: &::rustpython_vm::VirtualMachine) -> ::rustpython_vm::PyObjectRef {
4141
::rustpython_vm::PyStructSequence::into_struct_sequence(self, vm).into()
4242
}
4343
}

stdlib/src/array.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod array {
1818
},
1919
class_or_notimplemented,
2020
function::{
21-
ArgBytesLike, ArgIntoFloat, ArgIterable, IntoPyObject, IntoPyResult, OptionalArg,
22-
PyComparisonValue,
21+
ArgBytesLike, ArgIntoFloat, ArgIterable, OptionalArg, PyComparisonValue,
22+
ToPyObject, ToPyResult,
2323
},
2424
protocol::{
2525
BufferDescriptor, BufferMethods, BufferResizeGuard, PyBuffer, PyIterReturn,
@@ -117,7 +117,7 @@ mod array {
117117
let i = v.wrap_index(i).ok_or_else(|| {
118118
vm.new_index_error("pop index out of range".to_owned())
119119
})?;
120-
v.remove(i).into_pyresult(vm)
120+
v.remove(i).to_pyresult(vm)
121121
})*
122122
}
123123
}
@@ -258,15 +258,15 @@ mod array {
258258
) -> Option<PyResult> {
259259
match self {
260260
$(ArrayContentType::$n(v) => {
261-
v.get(i).map(|x| x.into_pyresult(vm))
261+
v.get(i).map(|x| x.to_pyresult(vm))
262262
})*
263263
}
264264
}
265265

266266
fn getitem_by_index(&self, i: isize, vm: &VirtualMachine) -> PyResult {
267267
match self {
268268
$(ArrayContentType::$n(v) => {
269-
v.get_item_by_index(vm, i).map(|x| x.into_pyresult(vm))?
269+
v.get_item_by_index(vm, i).map(|x| x.to_pyresult(vm))?
270270
})*
271271
}
272272
}
@@ -276,7 +276,7 @@ mod array {
276276
$(ArrayContentType::$n(v) => {
277277
let r = v.get_item_by_slice(vm, slice)?;
278278
let array = PyArray::from(ArrayContentType::$n(r));
279-
array.into_pyresult(vm)
279+
array.to_pyresult(vm)
280280
})*
281281
}
282282
}
@@ -568,11 +568,11 @@ mod array {
568568
}
569569
}
570570

571-
impl IntoPyResult for WideChar {
572-
fn into_pyresult(self, vm: &VirtualMachine) -> PyResult {
571+
impl ToPyResult for WideChar {
572+
fn to_pyresult(self, vm: &VirtualMachine) -> PyResult {
573573
Ok(
574574
String::from(char::try_from(self).map_err(|e| vm.new_unicode_encode_error(e))?)
575-
.into_pyobject(vm),
575+
.to_pyobject(vm),
576576
)
577577
}
578578
}
@@ -1139,7 +1139,7 @@ mod array {
11391139
let typecode = vm.ctx.new_str(array.typecode_str());
11401140
let values = if array.typecode() == 'u' {
11411141
let s = Self::_wchar_bytes_to_string(array.get_bytes(), array.itemsize(), vm)?;
1142-
s.chars().map(|x| x.into_pyobject(vm)).collect()
1142+
s.chars().map(|x| x.to_pyobject(vm)).collect()
11431143
} else {
11441144
array.get_objects(vm)
11451145
};
@@ -1472,15 +1472,15 @@ mod array {
14721472
}
14731473
}};
14741474
($VM:ident, $BYTE:ident, $TY:ty, $BIG_ENDIAN:ident) => {
1475-
chunk_to_obj!($BYTE, $TY, $BIG_ENDIAN).into_pyobject($VM)
1475+
chunk_to_obj!($BYTE, $TY, $BIG_ENDIAN).to_pyobject($VM)
14761476
};
14771477
($VM:ident, $BYTE:ident, $SIGNED_TY:ty, $UNSIGNED_TY:ty, $SIGNED:ident, $BIG_ENDIAN:ident) => {{
14781478
let b = <[u8; ::std::mem::size_of::<$SIGNED_TY>()]>::try_from($BYTE).unwrap();
14791479
match ($SIGNED, $BIG_ENDIAN) {
1480-
(false, false) => <$UNSIGNED_TY>::from_le_bytes(b).into_pyobject($VM),
1481-
(false, true) => <$UNSIGNED_TY>::from_be_bytes(b).into_pyobject($VM),
1482-
(true, false) => <$SIGNED_TY>::from_le_bytes(b).into_pyobject($VM),
1483-
(true, true) => <$SIGNED_TY>::from_be_bytes(b).into_pyobject($VM),
1480+
(false, false) => <$UNSIGNED_TY>::from_le_bytes(b).to_pyobject($VM),
1481+
(false, true) => <$UNSIGNED_TY>::from_be_bytes(b).to_pyobject($VM),
1482+
(true, false) => <$SIGNED_TY>::from_le_bytes(b).to_pyobject($VM),
1483+
(true, true) => <$SIGNED_TY>::from_be_bytes(b).to_pyobject($VM),
14841484
}
14851485
}};
14861486
}

stdlib/src/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod _json {
66
use super::machinery;
77
use crate::vm::{
88
builtins::{PyBaseExceptionRef, PyStrRef, PyTypeRef},
9-
function::{IntoPyObject, IntoPyResult, OptionalArg},
9+
function::{OptionalArg, ToPyObject, ToPyResult},
1010
protocol::PyIterReturn,
1111
types::{Callable, Constructor},
1212
AsPyObject, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
@@ -85,7 +85,7 @@ mod _json {
8585
match c {
8686
'"' => {
8787
return scanstring(pystr, next_idx, OptionalArg::Present(self.strict), vm)
88-
.map(|x| PyIterReturn::Return(x.into_pyobject(vm)))
88+
.map(|x| PyIterReturn::Return(x.to_pyobject(vm)))
8989
}
9090
'{' => {
9191
// TODO: parse the object in rust
@@ -206,7 +206,7 @@ mod _json {
206206
let idx = idx as usize;
207207
let mut chars = pystr.as_str().chars();
208208
if idx > 0 && chars.nth(idx - 1).is_none() {
209-
PyIterReturn::StopIteration(Some(vm.ctx.new_int(idx).into())).into_pyresult(vm)
209+
PyIterReturn::StopIteration(Some(vm.ctx.new_int(idx).into())).to_pyresult(vm)
210210
} else {
211211
zelf.parse(
212212
chars.as_str(),
@@ -215,7 +215,7 @@ mod _json {
215215
zelf.to_owned().into(),
216216
vm,
217217
)
218-
.and_then(|x| x.into_pyresult(vm))
218+
.and_then(|x| x.to_pyresult(vm))
219219
}
220220
}
221221
}

stdlib/src/posixsubprocess.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) use _posixsubprocess::make_module;
1919
#[pymodule]
2020
mod _posixsubprocess {
2121
use super::{exec, CStrPathLike, ForkExecArgs, ProcArgs};
22-
use crate::vm::{function::IntoPyException, PyResult, VirtualMachine};
22+
use crate::vm::{function::ToPyException, PyResult, VirtualMachine};
2323

2424
#[pyfunction]
2525
fn fork_exec(args: ForkExecArgs, vm: &VirtualMachine) -> PyResult<libc::pid_t> {
@@ -37,7 +37,7 @@ mod _posixsubprocess {
3737
let argv = &argv;
3838
let envp = args.env_list.as_ref().map(|s| cstrs_to_ptrs(s.as_slice()));
3939
let envp = envp.as_deref();
40-
match unsafe { nix::unistd::fork() }.map_err(|err| err.into_pyexception(vm))? {
40+
match unsafe { nix::unistd::fork() }.map_err(|err| err.to_pyexception(vm))? {
4141
nix::unistd::ForkResult::Child => exec(&args, ProcArgs { argv, envp }),
4242
nix::unistd::ForkResult::Parent { child } => Ok(child.as_raw()),
4343
}

stdlib/src/re.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod re {
1010
*/
1111
use crate::vm::{
1212
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
13-
function::{IntoPyObject, OptionalArg, PosArgs},
13+
function::{ToPyObject, OptionalArg, PosArgs},
1414
match_class, PyObjectRef, PyResult, PyValue, TryFromObject, VirtualMachine,
1515
};
1616
use num_traits::Signed;
@@ -418,14 +418,14 @@ mod re {
418418
match groups.len() {
419419
0 => Ok(self
420420
.subgroup(self.captures[0].clone().unwrap())
421-
.into_pyobject(vm)),
421+
.to_pyobject(vm)),
422422
1 => self
423423
.get_group(groups.pop().unwrap(), vm)
424-
.map(|g| g.into_pyobject(vm)),
424+
.map(|g| g.to_pyobject(vm)),
425425
_ => {
426426
let output: Result<Vec<_>, _> = groups
427427
.into_iter()
428-
.map(|id| self.get_group(id, vm).map(|g| g.into_pyobject(vm)))
428+
.map(|id| self.get_group(id, vm).map(|g| g.to_pyobject(vm)))
429429
.collect();
430430
Ok(vm.ctx.new_tuple(output?)).into()
431431
}
@@ -442,7 +442,7 @@ mod re {
442442
vm.unwrap_or_none(
443443
capture
444444
.as_ref()
445-
.map(|bounds| self.subgroup(bounds.clone()).into_pyobject(vm))
445+
.map(|bounds| self.subgroup(bounds.clone()).to_pyobject(vm))
446446
.or_else(|| default.clone()),
447447
)
448448
})

stdlib/src/resource.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub(crate) use resource::make_module;
33
#[pymodule]
44
mod resource {
55
use crate::vm::{
6-
function::{IntoPyException, IntoPyObject},
6+
function::{ToPyException, ToPyObject},
77
stdlib::os,
88
PyObject, PyObjectRef, PyResult, PyStructSequence, TryFromBorrowedObject, VirtualMachine,
99
};
@@ -122,7 +122,7 @@ mod resource {
122122
if e.kind() == io::ErrorKind::InvalidInput {
123123
vm.new_value_error("invalid who parameter".to_owned())
124124
} else {
125-
e.into_pyexception(vm)
125+
e.to_pyexception(vm)
126126
}
127127
})
128128
}
@@ -140,9 +140,9 @@ mod resource {
140140
}
141141
}
142142
}
143-
impl IntoPyObject for Limits {
144-
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
145-
(self.0.rlim_cur, self.0.rlim_max).into_pyobject(vm)
143+
impl ToPyObject for Limits {
144+
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
145+
(self.0.rlim_cur, self.0.rlim_max).to_pyobject(vm)
146146
}
147147
}
148148

@@ -180,7 +180,7 @@ mod resource {
180180
io::ErrorKind::PermissionDenied => {
181181
vm.new_value_error("not allowed to raise maximum limit".to_owned())
182182
}
183-
_ => e.into_pyexception(vm),
183+
_ => e.to_pyexception(vm),
184184
})
185185
}
186186
}

stdlib/src/scproxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod _scproxy {
66

77
use crate::vm::{
88
builtins::{PyDictRef, PyStr},
9-
function::IntoPyObject,
9+
function::ToPyObject,
1010
PyResult, VirtualMachine,
1111
};
1212
use system_configuration::core_foundation::{
@@ -62,7 +62,7 @@ mod _scproxy {
6262
let a_string: std::borrow::Cow<str> = (&s).into();
6363
PyStr::from(a_string.into_owned())
6464
})
65-
.into_pyobject(vm)
65+
.to_pyobject(vm)
6666
})
6767
.collect();
6868
result.set_item("exceptions", vm.ctx.new_tuple(v).into(), vm)?;

stdlib/src/select.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ mod decl {
155155
use super::*;
156156
use crate::vm::{
157157
builtins::PyTypeRef,
158-
function::{IntoPyException, OptionalOption},
158+
function::{OptionalOption, ToPyException},
159159
stdlib::time,
160160
utils::Either,
161161
PyObjectRef, PyResult, VirtualMachine,
@@ -215,7 +215,7 @@ mod decl {
215215
match res {
216216
Ok(_) => break,
217217
Err(err) if err.kind() == io::ErrorKind::Interrupted => {}
218-
Err(err) => return Err(err.into_pyexception(vm)),
218+
Err(err) => return Err(err.to_pyexception(vm)),
219219
}
220220

221221
vm.check_signals()?;
@@ -264,7 +264,7 @@ mod decl {
264264
use crate::vm::{
265265
builtins::PyFloat,
266266
common::lock::PyMutex,
267-
function::{IntoPyObject, OptionalArg},
267+
function::{OptionalArg, ToPyObject},
268268
stdlib::io::Fildes,
269269
AsPyObject, PyValue,
270270
};
@@ -327,9 +327,8 @@ mod decl {
327327
vm: &VirtualMachine,
328328
) -> PyResult<()> {
329329
let mut fds = self.fds.lock();
330-
let pfd = get_fd_mut(&mut fds, fd).ok_or_else(|| {
331-
io::Error::from_raw_os_error(libc::ENOENT).into_pyexception(vm)
332-
})?;
330+
let pfd = get_fd_mut(&mut fds, fd)
331+
.ok_or_else(|| io::Error::from_raw_os_error(libc::ENOENT).to_pyexception(vm))?;
333332
pfd.events = eventmask as i16;
334333
Ok(())
335334
}
@@ -388,13 +387,13 @@ mod decl {
388387
}
389388
}
390389
}
391-
Err(e) => return Err(e.into_pyexception(vm)),
390+
Err(e) => return Err(e.to_pyexception(vm)),
392391
}
393392
}
394393
Ok(fds
395394
.iter()
396395
.filter(|pfd| pfd.revents != 0)
397-
.map(|pfd| (pfd.fd, pfd.revents & 0xfff).into_pyobject(vm))
396+
.map(|pfd| (pfd.fd, pfd.revents & 0xfff).to_pyobject(vm))
398397
.collect())
399398
}
400399
}

0 commit comments

Comments
 (0)