Skip to content

Commit 137a543

Browse files
committed
regroup use items for bulitin stdlibs
1 parent 96c9d9e commit 137a543

20 files changed

Lines changed: 159 additions & 201 deletions

vm/src/builtins/module.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010

1111
#[pyclass(module = false, name = "module")]
1212
#[derive(Debug)]
13-
pub struct PyModule {}
14-
pub type PyModuleRef = PyRef<PyModule>;
13+
pub struct PyModule;
1514

1615
impl PyValue for PyModule {
1716
fn class(vm: &VirtualMachine) -> &PyTypeRef {

vm/src/stdlib/ast.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
//! This module makes use of the parser logic, and translates all ast nodes
44
//! into python ast.AST objects.
55
6+
use crate::{
7+
builtins::{self, PyStrRef, PyTypeRef},
8+
function::FuncArgs,
9+
IdProtocol, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, PyValue, StaticType,
10+
TryFromObject, TypeProtocol, VirtualMachine,
11+
};
612
use num_complex::Complex64;
713
use num_traits::{ToPrimitive, Zero};
8-
914
use rustpython_ast as ast;
10-
11-
#[cfg(feature = "rustpython-parser")]
12-
use rustpython_parser::parser;
13-
1415
#[cfg(feature = "rustpython-compiler")]
1516
use rustpython_compiler as compile;
16-
17-
use crate::builtins::{self, PyStrRef, PyTypeRef};
18-
use crate::function::FuncArgs;
19-
use crate::vm::VirtualMachine;
20-
use crate::{
21-
IdProtocol, ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, PyValue, StaticType,
22-
TryFromObject, TypeProtocol,
23-
};
17+
#[cfg(feature = "rustpython-parser")]
18+
use rustpython_parser::parser;
2419

2520
#[rustfmt::skip]
2621
#[allow(clippy::all)]

vm/src/stdlib/atexit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ pub(crate) use atexit::make_module;
22

33
#[pymodule]
44
mod atexit {
5-
use crate::function::FuncArgs;
6-
use crate::VirtualMachine;
7-
use crate::{PyObjectRef, PyResult};
5+
use crate::{function::FuncArgs, PyObjectRef, PyResult, VirtualMachine};
86

97
#[pyfunction]
108
fn register(func: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/codecs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ pub(crate) use _codecs::make_module;
22

33
#[pymodule]
44
mod _codecs {
5-
use std::ops::Range;
6-
7-
use crate::builtins::{PyBytesRef, PyStr, PyStrRef, PyTuple};
8-
use crate::byteslike::ArgBytesLike;
9-
use crate::codecs;
105
use crate::common::encodings;
11-
use crate::exceptions::PyBaseExceptionRef;
12-
use crate::function::FuncArgs;
13-
use crate::VirtualMachine;
14-
use crate::{IdProtocol, PyObjectRef, PyResult, TryFromBorrowedObject};
6+
use crate::{
7+
builtins::{PyBytesRef, PyStr, PyStrRef, PyTuple},
8+
byteslike::ArgBytesLike,
9+
codecs,
10+
exceptions::PyBaseExceptionRef,
11+
function::FuncArgs,
12+
IdProtocol, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine,
13+
};
14+
use std::ops::Range;
1515

1616
#[pyfunction]
1717
fn register(search_function: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

vm/src/stdlib/collections.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ pub(crate) use _collections::make_module;
33
#[pymodule]
44
mod _collections {
55
use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard};
6-
use crate::function::{FuncArgs, KwArgs, OptionalArg};
7-
use crate::slots::{
8-
Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable,
9-
};
10-
use crate::vm::ReprGuard;
11-
use crate::VirtualMachine;
126
use crate::{
137
builtins::{
148
IterStatus::{self, Active, Exhausted},
159
PyInt, PyTypeRef,
1610
},
17-
TypeProtocol,
11+
function::{FuncArgs, KwArgs, OptionalArg},
12+
sequence, sliceable,
13+
slots::{
14+
Comparable, Hashable, Iterable, PyComparisonOp, PyIter, SlotConstructor, Unhashable,
15+
},
16+
vm::ReprGuard,
17+
PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TypeProtocol,
18+
VirtualMachine,
1819
};
19-
use crate::{sequence, sliceable};
20-
use crate::{PyComparisonValue, PyObjectRef, PyRef, PyResult, PyValue, StaticType};
2120
use crossbeam_utils::atomic::AtomicCell;
2221
use itertools::Itertools;
2322
use num_traits::ToPrimitive;

vm/src/stdlib/imp.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
use crate::builtins::bytes::PyBytesRef;
2-
use crate::builtins::code::PyCode;
3-
use crate::builtins::module::PyModuleRef;
4-
use crate::builtins::pystr::{PyStr, PyStrRef};
5-
use crate::import;
6-
use crate::vm::VirtualMachine;
7-
use crate::{ItemProtocol, PyObjectRef, PyResult, PyValue, TryFromObject};
1+
use crate::{
2+
builtins::{PyBytesRef, PyCode, PyModule, PyStr, PyStrRef},
3+
import, ItemProtocol, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
4+
};
85

96
#[cfg(feature = "threading")]
107
mod lock {
@@ -70,7 +67,7 @@ fn _imp_create_builtin(spec: PyObjectRef, vm: &VirtualMachine) -> PyResult {
7067
}
7168
}
7269

73-
fn _imp_exec_builtin(_mod: PyModuleRef) -> i32 {
70+
fn _imp_exec_builtin(_mod: PyRef<PyModule>) -> i32 {
7471
// TODO: Should we do something here?
7572
0
7673
}

vm/src/stdlib/io.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ cfg_if::cfg_if! {
1111

1212
#[cfg(unix)]
1313
use crate::stdlib::os::{errno_err, PathOrFd};
14-
use crate::VirtualMachine;
15-
use crate::{PyObjectRef, PyResult, TryFromObject};
14+
use crate::{PyObjectRef, PyResult, TryFromObject, VirtualMachine};
1615
pub(crate) use _io::io_open as open;
1716

1817
pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/itertools.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ pub(crate) use decl::make_module;
22

33
#[pymodule(name = "itertools")]
44
mod decl {
5+
use crate::common::{
6+
lock::{PyMutex, PyRwLock, PyRwLockWriteGuard},
7+
rc::PyRc,
8+
};
9+
use crate::{
10+
builtins::{int, PyInt, PyIntRef, PyTupleRef, PyTypeRef},
11+
function::{Args, FuncArgs, OptionalArg, OptionalOption},
12+
iterator::{call_next, get_iter, get_next_object},
13+
slots::{PyIter, SlotConstructor},
14+
IdProtocol, IntoPyObject, PyCallable, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef,
15+
StaticType, TypeProtocol, VirtualMachine,
16+
};
517
use crossbeam_utils::atomic::AtomicCell;
618
use num_bigint::BigInt;
719
use num_traits::{One, Signed, ToPrimitive, Zero};
820
use std::fmt;
921

10-
use crate::builtins::int::{self, PyInt, PyIntRef};
11-
use crate::builtins::pytype::PyTypeRef;
12-
use crate::builtins::tuple::PyTupleRef;
13-
use crate::common::lock::{PyMutex, PyRwLock, PyRwLockWriteGuard};
14-
use crate::common::rc::PyRc;
15-
use crate::function::{Args, FuncArgs, OptionalArg, OptionalOption};
16-
use crate::iterator::{call_next, get_iter, get_next_object};
17-
use crate::slots::{PyIter, SlotConstructor};
18-
use crate::vm::VirtualMachine;
19-
use crate::{
20-
IdProtocol, IntoPyObject, PyCallable, PyObjectRef, PyRef, PyResult, PyValue, PyWeakRef,
21-
StaticType, TypeProtocol,
22-
};
23-
2422
#[pyattr]
2523
#[pyclass(name = "chain")]
2624
#[derive(Debug, PyValue)]

vm/src/stdlib/marshal.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ pub(crate) use decl::make_module;
22

33
#[pymodule(name = "marshal")]
44
mod decl {
5-
use crate::builtins::bytes::PyBytes;
6-
use crate::builtins::code::{PyCode, PyCodeRef};
7-
use crate::bytecode;
8-
use crate::byteslike::ArgBytesLike;
9-
use crate::vm::VirtualMachine;
10-
use crate::{PyObjectRef, PyResult, TryFromObject};
5+
use crate::{
6+
builtins::{PyBytes, PyCode},
7+
bytecode,
8+
byteslike::ArgBytesLike,
9+
PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
10+
};
1111

1212
#[pyfunction]
13-
fn dumps(co: PyCodeRef) -> PyBytes {
13+
fn dumps(co: PyRef<PyCode>) -> PyBytes {
1414
PyBytes::from(co.code.map_clone_bag(&bytecode::BasicBag).to_bytes())
1515
}
1616

1717
#[pyfunction]
18-
fn dump(co: PyCodeRef, f: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
18+
fn dump(co: PyRef<PyCode>, f: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
1919
vm.call_method(&f, "write", (dumps(co),))?;
2020
Ok(())
2121
}

vm/src/stdlib/msvcrt.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use super::os::errno_err;
2-
use crate::builtins::bytes::PyBytesRef;
3-
use crate::builtins::pystr::PyStrRef;
4-
use crate::VirtualMachine;
5-
use crate::{PyObjectRef, PyResult};
6-
2+
use crate::{
3+
builtins::{PyBytes, PyStrRef},
4+
PyObjectRef, PyRef, PyResult, VirtualMachine,
5+
};
76
use itertools::Itertools;
8-
use winapi::shared::minwindef::UINT;
9-
use winapi::um::errhandlingapi::SetErrorMode;
10-
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
11-
use winapi::um::winnt::HANDLE;
7+
use winapi::{
8+
shared::minwindef::UINT,
9+
um::{errhandlingapi::SetErrorMode, handleapi::INVALID_HANDLE_VALUE, winnt::HANDLE},
10+
};
1211

1312
pub fn setmode_binary(fd: i32) {
1413
unsafe { suppress_iph!(_setmode(fd, libc::O_BINARY)) };
@@ -49,7 +48,7 @@ fn msvcrt_getwche() -> String {
4948
let c = unsafe { _getwche() };
5049
std::char::from_u32(c).unwrap().to_string()
5150
}
52-
fn msvcrt_putch(b: PyBytesRef, vm: &VirtualMachine) -> PyResult<()> {
51+
fn msvcrt_putch(b: PyRef<PyBytes>, vm: &VirtualMachine) -> PyResult<()> {
5352
let &c = b.as_bytes().iter().exactly_one().map_err(|_| {
5453
vm.new_type_error("putch() argument must be a byte string of length 1".to_owned())
5554
})?;

0 commit comments

Comments
 (0)