diff --git a/Cargo.toml b/Cargo.toml index 6c48714929..55cc120335 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,7 @@ members = [ [workspace.package] version = "0.4.0" authors = ["RustPython Team"] -edition = "2021" +edition = "2024" rust-version = "1.85.0" repository = "https://github.com/RustPython/RustPython" license = "MIT" diff --git a/benches/execution.rs b/benches/execution.rs index 6ec9b89f2a..57529bbb3a 100644 --- a/benches/execution.rs +++ b/benches/execution.rs @@ -1,11 +1,11 @@ use criterion::measurement::WallTime; use criterion::{ - black_box, criterion_group, criterion_main, Bencher, BenchmarkGroup, BenchmarkId, Criterion, - Throughput, + Bencher, BenchmarkGroup, BenchmarkId, Criterion, Throughput, black_box, criterion_group, + criterion_main, }; use rustpython_compiler::Mode; -use rustpython_parser::ast; use rustpython_parser::Parse; +use rustpython_parser::ast; use rustpython_vm::{Interpreter, PyResult, Settings}; use std::collections::HashMap; use std::path::Path; diff --git a/benches/microbenchmarks.rs b/benches/microbenchmarks.rs index b742b959b7..6f41f00d6c 100644 --- a/benches/microbenchmarks.rs +++ b/benches/microbenchmarks.rs @@ -1,6 +1,6 @@ use criterion::{ - criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId, - Criterion, Throughput, + BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main, + measurement::WallTime, }; use pyo3::types::PyAnyMethods; use rustpython_compiler::Mode; diff --git a/common/src/fileutils.rs b/common/src/fileutils.rs index 8713e11229..7d5ff01942 100644 --- a/common/src/fileutils.rs +++ b/common/src/fileutils.rs @@ -5,7 +5,7 @@ pub use libc::stat as StatStruct; #[cfg(windows)] -pub use windows::{fstat, StatStruct}; +pub use windows::{StatStruct, fstat}; #[cfg(not(windows))] pub fn fstat(fd: libc::c_int) -> std::io::Result { @@ -28,19 +28,19 @@ pub mod windows { use std::ffi::{CString, OsStr, OsString}; use std::os::windows::ffi::OsStrExt; use std::sync::OnceLock; - use windows_sys::core::PCWSTR; use windows_sys::Win32::Foundation::{ - FreeLibrary, SetLastError, BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME, - HANDLE, INVALID_HANDLE_VALUE, + BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME, FreeLibrary, HANDLE, + INVALID_HANDLE_VALUE, SetLastError, }; use windows_sys::Win32::Storage::FileSystem::{ - FileBasicInfo, FileIdInfo, GetFileInformationByHandle, GetFileInformationByHandleEx, - GetFileType, BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY, + BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_REPARSE_POINT, FILE_BASIC_INFO, FILE_ID_INFO, FILE_TYPE_CHAR, - FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN, + FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN, FileBasicInfo, FileIdInfo, + GetFileInformationByHandle, GetFileInformationByHandleEx, GetFileType, }; use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW}; use windows_sys::Win32::System::SystemServices::IO_REPARSE_TAG_SYMLINK; + use windows_sys::core::PCWSTR; pub const S_IFIFO: libc::c_int = 0o010000; pub const S_IFLNK: libc::c_int = 0o120000; diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index 8e16e71c14..46e2d57067 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -64,11 +64,7 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool { } pub fn div(v1: f64, v2: f64) -> Option { - if v2 != 0.0 { - Some(v1 / v2) - } else { - None - } + if v2 != 0.0 { Some(v1 / v2) } else { None } } pub fn mod_(v1: f64, v2: f64) -> Option { @@ -125,11 +121,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 { let b = x.to_bits(); let bits = if (y > x) == (x > 0.0) { b + 1 } else { b - 1 }; let ret = f64::from_bits(bits); - if ret == 0.0 { - ret.copysign(x) - } else { - ret - } + if ret == 0.0 { ret.copysign(x) } else { ret } } } diff --git a/common/src/hash.rs b/common/src/hash.rs index 5b5ac003cb..bbc30b1fe1 100644 --- a/common/src/hash.rs +++ b/common/src/hash.rs @@ -150,11 +150,7 @@ pub fn hash_bigint(value: &BigInt) -> PyHash { #[inline(always)] pub fn fix_sentinel(x: PyHash) -> PyHash { - if x == SENTINEL { - -2 - } else { - x - } + if x == SENTINEL { -2 } else { x } } #[inline] diff --git a/common/src/str.rs b/common/src/str.rs index 65b1e376cb..b4f7a1a636 100644 --- a/common/src/str.rs +++ b/common/src/str.rs @@ -241,11 +241,7 @@ pub mod levenshtein { if b.is_ascii_uppercase() { b += b'a' - b'A'; } - if a == b { - CASE_COST - } else { - MOVE_COST - } + if a == b { CASE_COST } else { MOVE_COST } } pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize { diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 7f8696baf2..6b1d15c720 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -8,21 +8,21 @@ #![deny(clippy::cast_possible_truncation)] use crate::{ + IndexSet, error::{CodegenError, CodegenErrorType}, ir, symboltable::{self, SymbolFlags, SymbolScope, SymbolTable}, - IndexSet, }; use itertools::Itertools; use num_complex::Complex64; use num_traits::ToPrimitive; use rustpython_ast::located::{self as located_ast, Located}; use rustpython_compiler_core::{ + Mode, bytecode::{ self, Arg as OpArgMarker, CodeObject, ComparisonOperator, ConstantData, Instruction, OpArg, OpArgType, }, - Mode, }; use rustpython_parser_core::source_code::{LineNumber, SourceLocation}; use std::borrow::Cow; @@ -975,7 +975,7 @@ impl Compiler { } } located_ast::Expr::BinOp(_) | located_ast::Expr::UnaryOp(_) => { - return Err(self.error(CodegenErrorType::Delete("expression"))) + return Err(self.error(CodegenErrorType::Delete("expression"))); } _ => return Err(self.error(CodegenErrorType::Delete(expression.python_name()))), } @@ -1213,7 +1213,7 @@ impl Compiler { if !finalbody.is_empty() { emit!(self, Instruction::PopBlock); // pop excepthandler block - // We enter the finally block, without exception. + // We enter the finally block, without exception. emit!(self, Instruction::EnterFinally); } @@ -3124,7 +3124,9 @@ impl Compiler { | "with_statement" | "print_function" | "unicode_literals" | "generator_stop" => {} "annotations" => self.future_annotations = true, other => { - return Err(self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned()))) + return Err( + self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned())) + ); } } } @@ -3477,8 +3479,8 @@ impl ToU32 for usize { #[cfg(test)] mod tests { use super::*; - use rustpython_parser::ast::Suite; use rustpython_parser::Parse; + use rustpython_parser::ast::Suite; use rustpython_parser_core::source_code::LinearLocator; fn compile_exec(source: &str) -> CodeObject { diff --git a/compiler/codegen/src/ir.rs b/compiler/codegen/src/ir.rs index 9f1a86e51d..08e68d283a 100644 --- a/compiler/codegen/src/ir.rs +++ b/compiler/codegen/src/ir.rs @@ -199,11 +199,7 @@ impl CodeInfo { }) .collect::>(); - if found_cellarg { - Some(cell2arg) - } else { - None - } + if found_cellarg { Some(cell2arg) } else { None } } fn dce(&mut self) { diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index 80c6e389fc..7db5c4edbe 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -8,8 +8,8 @@ Inspirational file: https://github.com/python/cpython/blob/main/Python/symtable. */ use crate::{ - error::{CodegenError, CodegenErrorType}, IndexMap, + error::{CodegenError, CodegenErrorType}, }; use bitflags::bitflags; use rustpython_ast::{self as ast, located::Located}; @@ -505,7 +505,10 @@ impl SymbolTableAnalyzer { // check if assignee is an iterator in top scope if parent_symbol.flags.contains(SymbolFlags::ITER) { return Err(SymbolTableError { - error: format!("assignment expression cannot rebind comprehension iteration variable {}", symbol.name), + error: format!( + "assignment expression cannot rebind comprehension iteration variable {}", + symbol.name + ), location: None, }); } @@ -1408,7 +1411,7 @@ impl SymbolTableBuilder { return Err(SymbolTableError { error: format!("cannot define nonlocal '{name}' at top level."), location, - }) + }); } _ => { // Ok! diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index c281058555..7d226cd1ce 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -1,9 +1,9 @@ use rustpython_codegen::{compile, symboltable}; -use rustpython_parser::ast::{self as ast, fold::Fold, ConstantOptimizer}; +use rustpython_parser::ast::{self as ast, ConstantOptimizer, fold::Fold}; pub use rustpython_codegen::compile::CompileOpts; -pub use rustpython_compiler_core::{bytecode::CodeObject, Mode}; -pub use rustpython_parser::{source_code::LinearLocator, Parse}; +pub use rustpython_compiler_core::{Mode, bytecode::CodeObject}; +pub use rustpython_parser::{Parse, source_code::LinearLocator}; // these modules are out of repository. re-exporting them here for convenience. pub use rustpython_codegen as codegen; diff --git a/derive-impl/src/compile_bytecode.rs b/derive-impl/src/compile_bytecode.rs index 34d5cb8d9d..2a57134197 100644 --- a/derive-impl/src/compile_bytecode.rs +++ b/derive-impl/src/compile_bytecode.rs @@ -17,17 +17,16 @@ use crate::Diagnostic; use once_cell::sync::Lazy; use proc_macro2::{Span, TokenStream}; use quote::quote; -use rustpython_compiler_core::{bytecode::CodeObject, frozen, Mode}; +use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen}; use std::{ collections::HashMap, env, fs, path::{Path, PathBuf}, }; use syn::{ - self, + self, LitByteStr, LitStr, Macro, parse::{ParseStream, Parser, Result as ParseResult}, spanned::Spanned, - LitByteStr, LitStr, Macro, }; static CARGO_MANIFEST_DIR: Lazy = Lazy::new(|| { @@ -118,11 +117,13 @@ impl CompilationSource { })?; self.compile_string(&source, mode, module_name, compiler, || rel_path.display()) } - CompilationSourceKind::SourceCode(code) => { - self.compile_string(&textwrap::dedent(code), mode, module_name, compiler, || { - "string literal" - }) - } + CompilationSourceKind::SourceCode(code) => self.compile_string( + &textwrap::dedent(code), + mode, + module_name, + compiler, + || "string literal", + ), CompilationSourceKind::Dir(_) => { unreachable!("Can't use compile_single with directory source") } diff --git a/derive-impl/src/from_args.rs b/derive-impl/src/from_args.rs index 47b0530d88..2273046ed4 100644 --- a/derive-impl/src/from_args.rs +++ b/derive-impl/src/from_args.rs @@ -1,8 +1,8 @@ use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; +use quote::{ToTokens, quote}; use syn::ext::IdentExt; use syn::meta::ParseNestedMeta; -use syn::{parse_quote, Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token}; +use syn::{Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token, parse_quote}; /// The kind of the python parameter, this corresponds to the value of Parameter.kind /// (https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind) diff --git a/derive-impl/src/pyclass.rs b/derive-impl/src/pyclass.rs index c3f148e2eb..077bd36bb8 100644 --- a/derive-impl/src/pyclass.rs +++ b/derive-impl/src/pyclass.rs @@ -1,14 +1,14 @@ use super::Diagnostic; use crate::util::{ - format_doc, pyclass_ident_and_attrs, pyexception_ident_and_attrs, text_signature, - ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta, ItemMeta, - ItemMetaInner, ItemNursery, SimpleItemMeta, ALL_ALLOWED_NAMES, + ALL_ALLOWED_NAMES, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta, + ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, format_doc, pyclass_ident_and_attrs, + pyexception_ident_and_attrs, text_signature, }; use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree}; -use quote::{quote, quote_spanned, ToTokens}; +use quote::{ToTokens, quote, quote_spanned}; use std::collections::{HashMap, HashSet}; use std::str::FromStr; -use syn::{parse_quote, spanned::Spanned, Attribute, Ident, Item, Result}; +use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned}; use syn_ext::ext::*; use syn_ext::types::*; @@ -126,7 +126,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul return Err(syn::Error::new_spanned( segment, "Py{Ref} is expected but Py{Ref} is found", - )) + )); } } } @@ -134,7 +134,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul return Err(syn::Error::new_spanned( segment, "Py{Ref} is expected but Py{Ref}? is found", - )) + )); } } } else { @@ -152,7 +152,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul return Err(syn::Error::new_spanned( imp.self_ty, "PyImpl can only be implemented for Py{Ref} or T", - )) + )); } }; @@ -1237,11 +1237,7 @@ impl MethodItemMeta { name } else { let name = inner.item_name(); - if magic { - format!("__{name}__") - } else { - name - } + if magic { format!("__{name}__") } else { name } }) } } @@ -1308,11 +1304,7 @@ impl GetSetItemMeta { GetSetItemKind::Set => extract_prefix_name("set_", "setter")?, GetSetItemKind::Delete => extract_prefix_name("del_", "deleter")?, }; - if magic { - format!("__{name}__") - } else { - name - } + if magic { format!("__{name}__") } else { name } }; Ok((py_name, kind)) } @@ -1488,7 +1480,10 @@ fn extract_impl_attrs(attr: PunctuatedNestedMeta, item: &Ident) -> Result { return Err( self.new_syn_error(other.span(), "can only be on a function, const and use") - ) + ); } }; diff --git a/derive-impl/src/util.rs b/derive-impl/src/util.rs index cfe54a5c72..7e0eb96fb0 100644 --- a/derive-impl/src/util.rs +++ b/derive-impl/src/util.rs @@ -1,8 +1,8 @@ use itertools::Itertools; use proc_macro2::{Span, TokenStream}; -use quote::{quote, ToTokens}; +use quote::{ToTokens, quote}; use std::collections::{HashMap, HashSet}; -use syn::{spanned::Spanned, Attribute, Ident, Result, Signature, UseTree}; +use syn::{Attribute, Ident, Result, Signature, UseTree, spanned::Spanned}; use syn_ext::{ ext::{AttributeExt as SynAttributeExt, *}, types::*, @@ -75,7 +75,7 @@ impl ItemNursery { impl ToTokens for ValidatedItemNursery { fn to_tokens(&self, tokens: &mut TokenStream) { - let mut sorted = self.0 .0.clone(); + let mut sorted = self.0.0.clone(); sorted.sort_by(|a, b| a.sort_order.cmp(&b.sort_order)); tokens.extend(sorted.iter().map(|item| { let cfgs = &item.cfgs; @@ -447,7 +447,7 @@ impl ItemMeta for ExceptionItemMeta { Self(ClassItemMeta(inner)) } fn inner(&self) -> &ItemMetaInner { - &self.0 .0 + &self.0.0 } } @@ -470,12 +470,12 @@ impl ExceptionItemMeta { let type_name = inner.item_name(); let Some(py_name) = type_name.as_str().strip_prefix("Py") else { bail_span!( - inner.item_ident, - "#[pyexception] expects its underlying type to be named `Py` prefixed" - ) + inner.item_ident, + "#[pyexception] expects its underlying type to be named `Py` prefixed" + ) }; py_name.to_string() - }) + }); } _ => {} } diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 9e94bf43cb..97ca026e76 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -245,7 +245,7 @@ impl derive_impl::Compiler for Compiler { mode: rustpython_compiler::Mode, module_name: String, ) -> Result> { - use rustpython_compiler::{compile, CompileOpts}; + use rustpython_compiler::{CompileOpts, compile}; Ok(compile(source, mode, module_name, CompileOpts::default())?) } } diff --git a/examples/call_between_rust_and_python.rs b/examples/call_between_rust_and_python.rs index 78eef62200..576390d059 100644 --- a/examples/call_between_rust_and_python.rs +++ b/examples/call_between_rust_and_python.rs @@ -1,5 +1,5 @@ use rustpython::vm::{ - pyclass, pymodule, PyObject, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, + PyObject, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, pyclass, pymodule, }; pub fn main() { @@ -31,7 +31,7 @@ pub fn main() { #[pymodule] mod rust_py_module { use super::*; - use rustpython::vm::{builtins::PyList, convert::ToPyObject, PyObjectRef}; + use rustpython::vm::{PyObjectRef, builtins::PyList, convert::ToPyObject}; #[pyfunction] fn rust_function( diff --git a/examples/generator.rs b/examples/generator.rs index 010ccd3797..937687ab8f 100644 --- a/examples/generator.rs +++ b/examples/generator.rs @@ -1,9 +1,9 @@ use rustpython_vm as vm; use std::process::ExitCode; use vm::{ + Interpreter, PyResult, builtins::PyIntRef, protocol::{PyIter, PyIterReturn}, - Interpreter, PyResult, }; fn py_main(interp: &Interpreter) -> vm::PyResult<()> { diff --git a/examples/package_embed.rs b/examples/package_embed.rs index fffa98623a..975e734593 100644 --- a/examples/package_embed.rs +++ b/examples/package_embed.rs @@ -1,6 +1,6 @@ use rustpython_vm as vm; use std::process::ExitCode; -use vm::{builtins::PyStrRef, Interpreter}; +use vm::{Interpreter, builtins::PyStrRef}; fn py_main(interp: &Interpreter) -> vm::PyResult { interp.enter(|vm| { diff --git a/examples/parse_folder.rs b/examples/parse_folder.rs index c10450e018..f54be635c8 100644 --- a/examples/parse_folder.rs +++ b/examples/parse_folder.rs @@ -12,7 +12,7 @@ extern crate env_logger; extern crate log; use clap::{App, Arg}; -use rustpython_parser::{ast, Parse}; +use rustpython_parser::{Parse, ast}; use std::{ path::Path, time::{Duration, Instant}, diff --git a/rustfmt.toml b/rustfmt.toml index 3a26366d4d..f216078d96 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -edition = "2021" +edition = "2024" diff --git a/src/interpreter.rs b/src/interpreter.rs index 9d4dc4ee98..35710ae829 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -1,4 +1,4 @@ -use rustpython_vm::{builtins::PyModule, Interpreter, PyRef, Settings, VirtualMachine}; +use rustpython_vm::{Interpreter, PyRef, Settings, VirtualMachine, builtins::PyModule}; pub type InitHook = Box; diff --git a/src/lib.rs b/src/lib.rs index 9fa38b968c..b0a176acf2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,14 +50,14 @@ mod interpreter; mod settings; mod shell; -use rustpython_vm::{scope::Scope, PyResult, VirtualMachine}; +use rustpython_vm::{PyResult, VirtualMachine, scope::Scope}; use std::env; use std::io::IsTerminal; use std::process::ExitCode; pub use interpreter::InterpreterConfig; pub use rustpython_vm as vm; -pub use settings::{opts_with_clap, InstallPipMode, RunMode}; +pub use settings::{InstallPipMode, RunMode, opts_with_clap}; pub use shell::run_shell; /// The main cli of the `rustpython` interpreter. This function will return `std::process::ExitCode` diff --git a/src/settings.rs b/src/settings.rs index f6b7f21f25..35114374c8 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -238,7 +238,9 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) { settings.int_max_str_digits = match env::var("PYTHONINTMAXSTRDIGITS").unwrap().parse() { Ok(digits @ (0 | 640..)) => digits, _ => { - error!("Fatal Python error: config_init_int_max_str_digits: PYTHONINTMAXSTRDIGITS: invalid limit; must be >= 640 or 0 for unlimited.\nPython runtime state: preinitialized"); + error!( + "Fatal Python error: config_init_int_max_str_digits: PYTHONINTMAXSTRDIGITS: invalid limit; must be >= 640 or 0 for unlimited.\nPython runtime state: preinitialized" + ); std::process::exit(1); } }; diff --git a/src/shell.rs b/src/shell.rs index 91becb0bbf..00b6710061 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -1,12 +1,12 @@ mod helper; -use rustpython_parser::{lexer::LexicalErrorType, ParseErrorType, Tok}; +use rustpython_parser::{ParseErrorType, Tok, lexer::LexicalErrorType}; use rustpython_vm::{ + AsObject, PyResult, VirtualMachine, builtins::PyBaseExceptionRef, compiler::{self, CompileError, CompileErrorType}, readline::{Readline, ReadlineResult}, scope::Scope, - AsObject, PyResult, VirtualMachine, }; enum ShellExecResult { diff --git a/src/shell/helper.rs b/src/shell/helper.rs index 4d663b9424..0fe2f5ca93 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -1,8 +1,9 @@ #![cfg_attr(target_arch = "wasm32", allow(dead_code))] use rustpython_vm::{ + AsObject, PyResult, TryFromObject, VirtualMachine, builtins::{PyDictRef, PyStrRef}, function::ArgIterable, - identifier, AsObject, PyResult, TryFromObject, VirtualMachine, + identifier, }; pub struct ShellHelper<'vm> { diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 9bd58f8043..494e98dc1b 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -1,6 +1,6 @@ // spell-checker:ignore typecode tofile tolist fromfile -use rustpython_vm::{builtins::PyModule, PyRef, VirtualMachine}; +use rustpython_vm::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let module = array::make_module(vm); @@ -41,6 +41,7 @@ mod array { str::wchar_t, }, vm::{ + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, builtins::{ PositionIterInternal, PyByteArray, PyBytes, PyBytesRef, PyDictRef, PyFloat, PyInt, @@ -64,7 +65,6 @@ mod array { AsBuffer, AsMapping, AsSequence, Comparable, Constructor, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, }, - AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }, }; use itertools::Itertools; @@ -1528,7 +1528,7 @@ mod array { 2 => Some(Self::Utf16 { big_endian }), 4 => Some(Self::Utf32 { big_endian }), _ => None, - } + }; } 'f' => { // Copied from CPython diff --git a/stdlib/src/binascii.rs b/stdlib/src/binascii.rs index eb11645879..ce3f9febd5 100644 --- a/stdlib/src/binascii.rs +++ b/stdlib/src/binascii.rs @@ -2,7 +2,7 @@ pub(super) use decl::crc32; pub(crate) use decl::make_module; -use rustpython_vm::{builtins::PyBaseExceptionRef, convert::ToPyException, VirtualMachine}; +use rustpython_vm::{VirtualMachine, builtins::PyBaseExceptionRef, convert::ToPyException}; const PAD: u8 = 61u8; const MAXLINESIZE: usize = 76; // Excluding the CRLF @@ -11,10 +11,10 @@ const MAXLINESIZE: usize = 76; // Excluding the CRLF mod decl { use super::{MAXLINESIZE, PAD}; use crate::vm::{ + PyResult, VirtualMachine, builtins::{PyIntRef, PyTypeRef}, convert::ToPyException, function::{ArgAsciiBuffer, ArgBytesLike, OptionalArg}, - PyResult, VirtualMachine, }; use itertools::Itertools; @@ -751,7 +751,10 @@ impl ToPyException for Base64DecodeError { InvalidByte(_, _) => "Only base64 data is allowed".to_owned(), InvalidLastSymbol(_, PAD) => "Excess data after padding".to_owned(), InvalidLastSymbol(length, _) => { - format!("Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4", length) + format!( + "Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4", + length + ) } InvalidLength => "Incorrect padding".to_owned(), }; diff --git a/stdlib/src/bisect.rs b/stdlib/src/bisect.rs index aaab65d788..4d67ee50b9 100644 --- a/stdlib/src/bisect.rs +++ b/stdlib/src/bisect.rs @@ -3,9 +3,9 @@ pub(crate) use _bisect::make_module; #[pymodule] mod _bisect { use crate::vm::{ + PyObjectRef, PyResult, VirtualMachine, function::{ArgIndex, OptionalArg}, types::PyComparisonOp, - PyObjectRef, PyResult, VirtualMachine, }; #[derive(FromArgs)] diff --git a/stdlib/src/blake2.rs b/stdlib/src/blake2.rs index 9b7da3327c..4209c966e8 100644 --- a/stdlib/src/blake2.rs +++ b/stdlib/src/blake2.rs @@ -4,7 +4,7 @@ pub(crate) use _blake2::make_module; #[pymodule] mod _blake2 { - use crate::hashlib::_hashlib::{local_blake2b, local_blake2s, BlakeHashArgs}; + use crate::hashlib::_hashlib::{BlakeHashArgs, local_blake2b, local_blake2s}; use crate::vm::{PyPayload, PyResult, VirtualMachine}; #[pyfunction] diff --git a/stdlib/src/bz2.rs b/stdlib/src/bz2.rs index f150b06eb8..ba74a38db1 100644 --- a/stdlib/src/bz2.rs +++ b/stdlib/src/bz2.rs @@ -6,13 +6,13 @@ pub(crate) use _bz2::make_module; mod _bz2 { use crate::common::lock::PyMutex; use crate::vm::{ + VirtualMachine, builtins::{PyBytesRef, PyTypeRef}, function::{ArgBytesLike, OptionalArg}, object::{PyPayload, PyResult}, types::Constructor, - VirtualMachine, }; - use bzip2::{write::BzEncoder, Decompress, Status}; + use bzip2::{Decompress, Status, write::BzEncoder}; use std::{fmt, io::Write}; // const BUFSIZ: i32 = 8192; @@ -196,7 +196,7 @@ mod _bz2 { _ => { return Err( vm.new_value_error("compresslevel must be between 1 and 9".to_owned()) - ) + ); } }; diff --git a/stdlib/src/cmath.rs b/stdlib/src/cmath.rs index c5badcf72a..4611ea344e 100644 --- a/stdlib/src/cmath.rs +++ b/stdlib/src/cmath.rs @@ -4,8 +4,8 @@ pub(crate) use cmath::make_module; #[pymodule] mod cmath { use crate::vm::{ - function::{ArgIntoComplex, ArgIntoFloat, OptionalArg}, PyResult, VirtualMachine, + function::{ArgIntoComplex, ArgIntoFloat, OptionalArg}, }; use num_complex::Complex64; diff --git a/stdlib/src/contextvars.rs b/stdlib/src/contextvars.rs index 40a59050b3..1e27b8b9e5 100644 --- a/stdlib/src/contextvars.rs +++ b/stdlib/src/contextvars.rs @@ -1,4 +1,4 @@ -use crate::vm::{builtins::PyModule, class::StaticType, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule, class::StaticType}; use _contextvars::PyContext; use std::cell::RefCell; @@ -23,14 +23,13 @@ thread_local! { #[pymodule] mod _contextvars { use crate::vm::{ - atomic_func, + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, builtins::{PyStrRef, PyTypeRef}, class::StaticType, common::hash::PyHash, function::{ArgCallable, FuncArgs, OptionalArg}, protocol::{PyMappingMethods, PySequenceMethods}, types::{AsMapping, AsSequence, Constructor, Hashable, Representable}, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use indexmap::IndexMap; diff --git a/stdlib/src/csv.rs b/stdlib/src/csv.rs index 7b3448e6b5..03a5429ba4 100644 --- a/stdlib/src/csv.rs +++ b/stdlib/src/csv.rs @@ -4,11 +4,11 @@ pub(crate) use _csv::make_module; mod _csv { use crate::common::lock::PyMutex; use crate::vm::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyInt, PyNone, PyStr, PyType, PyTypeError, PyTypeRef}, function::{ArgIterable, ArgumentError, FromArgs, FuncArgs, OptionalArg}, protocol::{PyIter, PyIterReturn}, types::{Constructor, IterNext, Iterable, SelfIter}, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use csv_core::Terminator; use itertools::{self, Itertools}; @@ -396,7 +396,7 @@ mod _csv { Some(write_meth) => write_meth, None if file.is_callable() => file, None => { - return Err(vm.new_type_error("argument 1 must have a \"write\" method".to_owned())) + return Err(vm.new_type_error("argument 1 must have a \"write\" method".to_owned())); } }; @@ -995,7 +995,7 @@ mod _csv { csv_core::ReadRecordResult::OutputEndsFull => resize_buf(output_ends), csv_core::ReadRecordResult::Record => break, csv_core::ReadRecordResult::End => { - return Ok(PyIterReturn::StopIteration(None)) + return Ok(PyIterReturn::StopIteration(None)); } } } diff --git a/stdlib/src/dis.rs b/stdlib/src/dis.rs index 12c2ea75df..69767ffbba 100644 --- a/stdlib/src/dis.rs +++ b/stdlib/src/dis.rs @@ -3,9 +3,9 @@ pub(crate) use decl::make_module; #[pymodule(name = "dis")] mod decl { use crate::vm::{ + PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyCode, PyDictRef, PyStrRef}, bytecode::CodeFlags, - PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine, }; #[pyfunction] diff --git a/stdlib/src/faulthandler.rs b/stdlib/src/faulthandler.rs index 2fb93ecc88..9ffd931291 100644 --- a/stdlib/src/faulthandler.rs +++ b/stdlib/src/faulthandler.rs @@ -2,7 +2,7 @@ pub(crate) use decl::make_module; #[pymodule(name = "faulthandler")] mod decl { - use crate::vm::{frame::Frame, function::OptionalArg, stdlib::sys::PyStderr, VirtualMachine}; + use crate::vm::{VirtualMachine, frame::Frame, function::OptionalArg, stdlib::sys::PyStderr}; fn dump_frame(frame: &Frame, vm: &VirtualMachine) { let stderr = PyStderr(vm); diff --git a/stdlib/src/fcntl.rs b/stdlib/src/fcntl.rs index ee73e50397..307d6e4351 100644 --- a/stdlib/src/fcntl.rs +++ b/stdlib/src/fcntl.rs @@ -3,10 +3,10 @@ pub(crate) use fcntl::make_module; #[pymodule] mod fcntl { use crate::vm::{ + PyResult, VirtualMachine, builtins::PyIntRef, function::{ArgMemoryBuffer, ArgStrOrBytesLike, Either, OptionalArg}, stdlib::{io, os}, - PyResult, VirtualMachine, }; // TODO: supply these from (please file an issue/PR upstream): @@ -20,7 +20,7 @@ mod fcntl { // I_LINK, I_UNLINK, I_PLINK, I_PUNLINK #[pyattr] - use libc::{FD_CLOEXEC, F_GETFD, F_GETFL, F_SETFD, F_SETFL}; + use libc::{F_GETFD, F_GETFL, F_SETFD, F_SETFL, FD_CLOEXEC}; #[cfg(not(target_os = "wasi"))] #[pyattr] @@ -45,7 +45,7 @@ mod fcntl { #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] #[pyattr] use libc::{ - F_ADD_SEALS, F_GETLEASE, F_GETPIPE_SZ, F_GET_SEALS, F_NOTIFY, F_SEAL_GROW, F_SEAL_SEAL, + F_ADD_SEALS, F_GET_SEALS, F_GETLEASE, F_GETPIPE_SZ, F_NOTIFY, F_SEAL_GROW, F_SEAL_SEAL, F_SEAL_SHRINK, F_SEAL_WRITE, F_SETLEASE, F_SETPIPE_SZ, }; diff --git a/stdlib/src/gc.rs b/stdlib/src/gc.rs index c78eea9c29..6e906ebab2 100644 --- a/stdlib/src/gc.rs +++ b/stdlib/src/gc.rs @@ -2,7 +2,7 @@ pub(crate) use gc::make_module; #[pymodule] mod gc { - use crate::vm::{function::FuncArgs, PyResult, VirtualMachine}; + use crate::vm::{PyResult, VirtualMachine, function::FuncArgs}; #[pyfunction] fn collect(_args: FuncArgs, _vm: &VirtualMachine) -> i32 { diff --git a/stdlib/src/grp.rs b/stdlib/src/grp.rs index d3eb0848bb..2cdad56588 100644 --- a/stdlib/src/grp.rs +++ b/stdlib/src/grp.rs @@ -3,11 +3,11 @@ pub(crate) use grp::make_module; #[pymodule] mod grp { use crate::vm::{ + PyObjectRef, PyResult, VirtualMachine, builtins::{PyIntRef, PyListRef, PyStrRef}, convert::{IntoPyException, ToPyObject}, exceptions, types::PyStructSequence, - PyObjectRef, PyResult, VirtualMachine, }; use nix::unistd; use std::ptr::NonNull; diff --git a/stdlib/src/hashlib.rs b/stdlib/src/hashlib.rs index 6944c37f9d..6124b6d242 100644 --- a/stdlib/src/hashlib.rs +++ b/stdlib/src/hashlib.rs @@ -6,16 +6,16 @@ pub(crate) use _hashlib::make_module; pub mod _hashlib { use crate::common::lock::PyRwLock; use crate::vm::{ + PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyBytes, PyStrRef, PyTypeRef}, convert::ToPyObject, function::{ArgBytesLike, ArgStrOrBytesLike, FuncArgs, OptionalArg}, protocol::PyBuffer, - PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use blake2::{Blake2b512, Blake2s256}; - use digest::{core_api::BlockSizeUser, DynDigest}; + use digest::{DynDigest, core_api::BlockSizeUser}; use digest::{ExtendableOutput, Update}; - use dyn_clone::{clone_trait_object, DynClone}; + use dyn_clone::{DynClone, clone_trait_object}; use md5::Md5; use sha1::Sha1; use sha2::{Sha224, Sha256, Sha384, Sha512}; diff --git a/stdlib/src/json.rs b/stdlib/src/json.rs index 921e545e5d..aaac0b8bef 100644 --- a/stdlib/src/json.rs +++ b/stdlib/src/json.rs @@ -5,12 +5,12 @@ mod machinery; mod _json { use super::machinery; use crate::vm::{ + AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef}, convert::{ToPyObject, ToPyResult}, function::{IntoFuncArgs, OptionalArg}, protocol::PyIterReturn, types::{Callable, Constructor}, - AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use malachite_bigint::BigInt; use std::str::FromStr; @@ -80,14 +80,14 @@ mod _json { None => { return Ok(PyIterReturn::StopIteration(Some( vm.ctx.new_int(idx).into(), - ))) + ))); } }; let next_idx = idx + c.len_utf8(); match c { '"' => { return scanstring(pystr, next_idx, OptionalArg::Present(self.strict), vm) - .map(|x| PyIterReturn::Return(x.to_pyobject(vm))) + .map(|x| PyIterReturn::Return(x.to_pyobject(vm))); } '{' => { // TODO: parse the object in rust diff --git a/stdlib/src/locale.rs b/stdlib/src/locale.rs index 8e44508fb6..9ca71a0957 100644 --- a/stdlib/src/locale.rs +++ b/stdlib/src/locale.rs @@ -40,10 +40,10 @@ use libc::localeconv; #[pymodule] mod _locale { use rustpython_vm::{ + PyObjectRef, PyResult, VirtualMachine, builtins::{PyDictRef, PyIntRef, PyListRef, PyStrRef, PyTypeRef}, convert::ToPyException, function::OptionalArg, - PyObjectRef, PyResult, VirtualMachine, }; use std::{ ffi::{CStr, CString}, @@ -56,12 +56,12 @@ mod _locale { ))] #[pyattr] use libc::{ - ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABMON_1, ABMON_10, ABMON_11, - ABMON_12, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, - ALT_DIGITS, AM_STR, CODESET, CRNCYSTR, DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, - D_FMT, D_T_FMT, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT, LC_MESSAGES, MON_1, MON_10, MON_11, - MON_12, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, NOEXPR, PM_STR, RADIXCHAR, - THOUSEP, T_FMT, T_FMT_AMPM, YESEXPR, + ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABMON_1, ABMON_2, ABMON_3, + ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12, + ALT_DIGITS, AM_STR, CODESET, CRNCYSTR, D_FMT, D_T_FMT, DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, + DAY_6, DAY_7, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT, LC_MESSAGES, MON_1, MON_2, MON_3, + MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12, NOEXPR, PM_STR, + RADIXCHAR, T_FMT, T_FMT_AMPM, THOUSEP, YESEXPR, }; #[pyattr] @@ -148,9 +148,7 @@ mod _locale { } macro_rules! set_int_field { - ($lc:expr, $field:ident) => {{ - result.set_item(stringify!($field), vm.new_pyobj((*$lc).$field), vm)? - }}; + ($lc:expr, $field:ident) => {{ result.set_item(stringify!($field), vm.new_pyobj((*$lc).$field), vm)? }}; } macro_rules! set_group_field { diff --git a/stdlib/src/math.rs b/stdlib/src/math.rs index 68930cfd0f..f86ebb591e 100644 --- a/stdlib/src/math.rs +++ b/stdlib/src/math.rs @@ -3,9 +3,10 @@ pub(crate) use math::make_module; #[pymodule] mod math { use crate::vm::{ - builtins::{try_bigint_to_f64, try_f64_to_bigint, PyFloat, PyInt, PyIntRef, PyStrInterned}, + PyObject, PyObjectRef, PyRef, PyResult, VirtualMachine, + builtins::{PyFloat, PyInt, PyIntRef, PyStrInterned, try_bigint_to_f64, try_f64_to_bigint}, function::{ArgIndex, ArgIntoFloat, ArgIterable, Either, OptionalArg, PosArgs}, - identifier, PyObject, PyObjectRef, PyRef, PyResult, VirtualMachine, + identifier, }; use itertools::Itertools; use malachite_bigint::BigInt; @@ -475,21 +476,13 @@ mod math { #[pyfunction] fn erf(x: ArgIntoFloat) -> f64 { let x = *x; - if x.is_nan() { - x - } else { - puruspe::erf(x) - } + if x.is_nan() { x } else { puruspe::erf(x) } } #[pyfunction] fn erfc(x: ArgIntoFloat) -> f64 { let x = *x; - if x.is_nan() { - x - } else { - puruspe::erfc(x) - } + if x.is_nan() { x } else { puruspe::erfc(x) } } #[pyfunction] diff --git a/stdlib/src/md5.rs b/stdlib/src/md5.rs index 833d217f5b..dca48242bb 100644 --- a/stdlib/src/md5.rs +++ b/stdlib/src/md5.rs @@ -2,7 +2,7 @@ pub(crate) use _md5::make_module; #[pymodule] mod _md5 { - use crate::hashlib::_hashlib::{local_md5, HashArgs}; + use crate::hashlib::_hashlib::{HashArgs, local_md5}; use crate::vm::{PyPayload, PyResult, VirtualMachine}; #[pyfunction] diff --git a/stdlib/src/mmap.rs b/stdlib/src/mmap.rs index aed665222e..e96339c370 100644 --- a/stdlib/src/mmap.rs +++ b/stdlib/src/mmap.rs @@ -8,7 +8,8 @@ mod mmap { lock::{MapImmutable, PyMutex, PyMutexGuard}, }; use crate::vm::{ - atomic_func, + AsObject, FromArgs, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, VirtualMachine, atomic_func, builtins::{PyBytes, PyBytesRef, PyInt, PyIntRef, PyTypeRef}, byte::{bytes_from_object, value_from_object}, convert::ToPyException, @@ -18,8 +19,6 @@ mod mmap { }, sliceable::{SaturatedSlice, SequenceIndex, SequenceIndexOp}, types::{AsBuffer, AsMapping, AsSequence, Constructor, Representable}, - AsObject, FromArgs, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use memmap2::{Advice, Mmap, MmapMut, MmapOptions}; diff --git a/stdlib/src/multiprocessing.rs b/stdlib/src/multiprocessing.rs index a6d902eb63..2db922e16b 100644 --- a/stdlib/src/multiprocessing.rs +++ b/stdlib/src/multiprocessing.rs @@ -3,7 +3,7 @@ pub(crate) use _multiprocessing::make_module; #[cfg(windows)] #[pymodule] mod _multiprocessing { - use crate::vm::{function::ArgBytesLike, stdlib::os, PyResult, VirtualMachine}; + use crate::vm::{PyResult, VirtualMachine, function::ArgBytesLike, stdlib::os}; use windows_sys::Win32::Networking::WinSock::{self, SOCKET}; #[pyfunction] diff --git a/stdlib/src/overlapped.rs b/stdlib/src/overlapped.rs index 9d08d88bcd..45eac5f51b 100644 --- a/stdlib/src/overlapped.rs +++ b/stdlib/src/overlapped.rs @@ -6,13 +6,13 @@ mod _overlapped { // straight-forward port of Modules/overlapped.c use crate::vm::{ + Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytesRef, PyTypeRef}, common::lock::PyMutex, convert::{ToPyException, ToPyObject}, protocol::PyBuffer, stdlib::os::errno_err, types::Constructor, - Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use windows_sys::Win32::{ Foundation::{self, GetLastError, HANDLE}, diff --git a/stdlib/src/posixsubprocess.rs b/stdlib/src/posixsubprocess.rs index 64e897b607..cff00a70aa 100644 --- a/stdlib/src/posixsubprocess.rs +++ b/stdlib/src/posixsubprocess.rs @@ -28,7 +28,7 @@ mod _posixsubprocess { use rustpython_vm::{AsObject, TryFromBorrowedObject}; use super::*; - use crate::vm::{convert::IntoPyException, PyResult, VirtualMachine}; + use crate::vm::{PyResult, VirtualMachine, convert::IntoPyException}; #[pyfunction] fn fork_exec(args: ForkExecArgs, vm: &VirtualMachine) -> PyResult { diff --git a/stdlib/src/pyexpat.rs b/stdlib/src/pyexpat.rs index 89267d3f7e..3cfe048f17 100644 --- a/stdlib/src/pyexpat.rs +++ b/stdlib/src/pyexpat.rs @@ -3,7 +3,7 @@ * */ -use crate::vm::{builtins::PyModule, extend_module, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule, extend_module}; pub fn make_module(vm: &VirtualMachine) -> PyRef { let module = _pyexpat::make_module(vm); @@ -32,10 +32,10 @@ macro_rules! create_property { #[pymodule(name = "pyexpat")] mod _pyexpat { use crate::vm::{ + Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyStr, PyStrRef, PyType}, function::ArgBytesLike, function::{IntoFuncArgs, OptionalArg}, - Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use rustpython_common::lock::PyRwLock; use std::io::Cursor; diff --git a/stdlib/src/pystruct.rs b/stdlib/src/pystruct.rs index 2d83e9570d..f8d41414f7 100644 --- a/stdlib/src/pystruct.rs +++ b/stdlib/src/pystruct.rs @@ -10,13 +10,13 @@ pub(crate) use _struct::make_module; #[pymodule] pub(crate) mod _struct { use crate::vm::{ - buffer::{new_struct_error, struct_error_type, FormatSpec}, + AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, + buffer::{FormatSpec, new_struct_error, struct_error_type}, builtins::{PyBytes, PyStr, PyStrRef, PyTupleRef, PyTypeRef}, function::{ArgBytesLike, ArgMemoryBuffer, PosArgs}, match_class, protocol::PyIterReturn, types::{Constructor, IterNext, Iterable, SelfIter}, - AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; diff --git a/stdlib/src/random.rs b/stdlib/src/random.rs index 0692e3ef9b..685c0ae8b9 100644 --- a/stdlib/src/random.rs +++ b/stdlib/src/random.rs @@ -6,11 +6,11 @@ pub(crate) use _random::make_module; mod _random { use crate::common::lock::PyMutex; use crate::vm::{ + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyInt, PyTupleRef}, convert::ToPyException, function::OptionalOption, types::{Constructor, Initializer}, - PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use itertools::Itertools; use malachite_bigint::{BigInt, BigUint, Sign}; @@ -75,11 +75,7 @@ mod _random { let mut rng = self.rng.lock(); let mut gen_u32 = |k| { let r = rng.next_u32(); - if k < 32 { - r >> (32 - k) - } else { - r - } + if k < 32 { r >> (32 - k) } else { r } }; let words = (k - 1) / 32 + 1; diff --git a/stdlib/src/resource.rs b/stdlib/src/resource.rs index c1b74f2b67..e103cce779 100644 --- a/stdlib/src/resource.rs +++ b/stdlib/src/resource.rs @@ -3,10 +3,10 @@ pub(crate) use resource::make_module; #[pymodule] mod resource { use crate::vm::{ + PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine, convert::{ToPyException, ToPyObject}, stdlib::os, types::PyStructSequence, - PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use std::{io, mem}; @@ -24,8 +24,8 @@ mod resource { // TODO: RLIMIT_OFILE, #[pyattr] use libc::{ - RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_MEMLOCK, - RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_STACK, RLIM_INFINITY, + RLIM_INFINITY, RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, + RLIMIT_MEMLOCK, RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_STACK, }; #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))] diff --git a/stdlib/src/scproxy.rs b/stdlib/src/scproxy.rs index 7108f50d8f..9bf29626ab 100644 --- a/stdlib/src/scproxy.rs +++ b/stdlib/src/scproxy.rs @@ -5,9 +5,9 @@ mod _scproxy { // straight-forward port of Modules/_scproxy.c use crate::vm::{ + PyResult, VirtualMachine, builtins::{PyDictRef, PyStr}, convert::ToPyObject, - PyResult, VirtualMachine, }; use system_configuration::core_foundation::{ array::CFArray, diff --git a/stdlib/src/select.rs b/stdlib/src/select.rs index 6554064d53..4003856bb9 100644 --- a/stdlib/src/select.rs +++ b/stdlib/src/select.rs @@ -1,6 +1,6 @@ use crate::vm::{ - builtins::PyListRef, builtins::PyModule, PyObject, PyObjectRef, PyRef, PyResult, TryFromObject, - VirtualMachine, + PyObject, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::PyListRef, + builtins::PyModule, }; use std::{io, mem}; @@ -19,7 +19,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[cfg(unix)] mod platform { - pub use libc::{fd_set, select, timeval, FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO}; + pub use libc::{FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO, fd_set, select, timeval}; pub use std::os::unix::io::RawFd; pub fn check_err(x: i32) -> bool { @@ -30,8 +30,8 @@ mod platform { #[allow(non_snake_case)] #[cfg(windows)] mod platform { + pub use WinSock::{FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval, select}; use windows_sys::Win32::Networking::WinSock; - pub use WinSock::{select, FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval}; // based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141 @@ -69,7 +69,7 @@ mod platform { #[cfg(target_os = "wasi")] mod platform { - pub use libc::{timeval, FD_SETSIZE}; + pub use libc::{FD_SETSIZE, timeval}; pub use std::os::wasi::io::RawFd; pub fn check_err(x: i32) -> bool { @@ -124,8 +124,8 @@ mod platform { } } -pub use platform::timeval; use platform::RawFd; +pub use platform::timeval; #[derive(Traverse)] struct Selectable { @@ -218,11 +218,11 @@ fn sec_to_timeval(sec: f64) -> timeval { mod decl { use super::*; use crate::vm::{ + PyObjectRef, PyResult, VirtualMachine, builtins::PyTypeRef, convert::ToPyException, function::{Either, OptionalOption}, stdlib::time, - PyObjectRef, PyResult, VirtualMachine, }; #[pyattr] @@ -327,12 +327,12 @@ mod decl { pub(super) mod poll { use super::*; use crate::vm::{ + AsObject, PyPayload, builtins::PyFloat, common::lock::PyMutex, convert::{IntoPyException, ToPyObject}, function::OptionalArg, stdlib::io::Fildes, - AsObject, PyPayload, }; use libc::pollfd; use num_traits::{Signed, ToPrimitive}; @@ -494,8 +494,9 @@ mod decl { #[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))] #[pyattr] use libc::{ - EPOLLERR, EPOLLEXCLUSIVE, EPOLLHUP, EPOLLIN, EPOLLMSG, EPOLLONESHOT, EPOLLOUT, EPOLLPRI, - EPOLLRDBAND, EPOLLRDHUP, EPOLLRDNORM, EPOLLWAKEUP, EPOLLWRBAND, EPOLLWRNORM, EPOLL_CLOEXEC, + EPOLL_CLOEXEC, EPOLLERR, EPOLLEXCLUSIVE, EPOLLHUP, EPOLLIN, EPOLLMSG, EPOLLONESHOT, + EPOLLOUT, EPOLLPRI, EPOLLRDBAND, EPOLLRDHUP, EPOLLRDNORM, EPOLLWAKEUP, EPOLLWRBAND, + EPOLLWRNORM, }; #[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))] #[pyattr] @@ -505,13 +506,13 @@ mod decl { pub(super) mod epoll { use super::*; use crate::vm::{ + PyPayload, builtins::PyTypeRef, common::lock::{PyRwLock, PyRwLockReadGuard}, convert::{IntoPyException, ToPyObject}, function::OptionalArg, stdlib::io::Fildes, types::Constructor, - PyPayload, }; use rustix::event::epoll::{self, EventData, EventFlags}; use std::ops::Deref; @@ -645,7 +646,7 @@ mod decl { ..-1 => { return Err(vm.new_value_error(format!( "maxevents must be greater than 0, got {maxevents}" - ))) + ))); } -1 => libc::FD_SETSIZE - 1, _ => maxevents as usize, diff --git a/stdlib/src/sha1.rs b/stdlib/src/sha1.rs index 3820e7d96a..04845bb76b 100644 --- a/stdlib/src/sha1.rs +++ b/stdlib/src/sha1.rs @@ -2,7 +2,7 @@ pub(crate) use _sha1::make_module; #[pymodule] mod _sha1 { - use crate::hashlib::_hashlib::{local_sha1, HashArgs}; + use crate::hashlib::_hashlib::{HashArgs, local_sha1}; use crate::vm::{PyPayload, PyResult, VirtualMachine}; #[pyfunction] diff --git a/stdlib/src/sha256.rs b/stdlib/src/sha256.rs index cae0172666..5d031968ae 100644 --- a/stdlib/src/sha256.rs +++ b/stdlib/src/sha256.rs @@ -1,4 +1,4 @@ -use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let _ = vm.import("_hashlib", 0); @@ -7,7 +7,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule] mod _sha256 { - use crate::hashlib::_hashlib::{local_sha224, local_sha256, HashArgs}; + use crate::hashlib::_hashlib::{HashArgs, local_sha224, local_sha256}; use crate::vm::{PyPayload, PyResult, VirtualMachine}; #[pyfunction] diff --git a/stdlib/src/sha3.rs b/stdlib/src/sha3.rs index f0c1c5ef69..07b61d9aed 100644 --- a/stdlib/src/sha3.rs +++ b/stdlib/src/sha3.rs @@ -3,8 +3,8 @@ pub(crate) use _sha3::make_module; #[pymodule] mod _sha3 { use crate::hashlib::_hashlib::{ - local_sha3_224, local_sha3_256, local_sha3_384, local_sha3_512, local_shake_128, - local_shake_256, HashArgs, + HashArgs, local_sha3_224, local_sha3_256, local_sha3_384, local_sha3_512, local_shake_128, + local_shake_256, }; use crate::vm::{PyPayload, PyResult, VirtualMachine}; diff --git a/stdlib/src/sha512.rs b/stdlib/src/sha512.rs index 8c510fb730..baf63fdacf 100644 --- a/stdlib/src/sha512.rs +++ b/stdlib/src/sha512.rs @@ -1,4 +1,4 @@ -use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let _ = vm.import("_hashlib", 0); @@ -7,7 +7,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule] mod _sha512 { - use crate::hashlib::_hashlib::{local_sha384, local_sha512, HashArgs}; + use crate::hashlib::_hashlib::{HashArgs, local_sha384, local_sha512}; use crate::vm::{PyPayload, PyResult, VirtualMachine}; #[pyfunction] diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 95f03ee4f8..a38b4f123c 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -1,6 +1,6 @@ -use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule}; #[cfg(feature = "ssl")] -pub(super) use _socket::{sock_select, timeout_error_msg, PySocket, SelectKind}; +pub(super) use _socket::{PySocket, SelectKind, sock_select, timeout_error_msg}; pub fn make_module(vm: &VirtualMachine) -> PyRef { #[cfg(windows)] @@ -12,13 +12,13 @@ pub fn make_module(vm: &VirtualMachine) -> PyRef { mod _socket { use crate::common::lock::{PyMappedRwLockReadGuard, PyRwLock, PyRwLockReadGuard}; use crate::vm::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyListRef, PyStrRef, PyTupleRef, PyTypeRef}, common::os::ErrorExt, convert::{IntoPyException, ToPyObject, TryFromBorrowedObject, TryFromObject}, function::{ArgBytesLike, ArgMemoryBuffer, Either, FsPath, OptionalArg, OptionalOption}, types::{Constructor, DefaultConstructor, Initializer, Representable}, utils::ToCString, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use num_traits::ToPrimitive; @@ -40,32 +40,33 @@ mod _socket { INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE, }; pub use winapi::um::winsock2::{ - getprotobyname, getservbyname, getservbyport, getsockopt, setsockopt, - SO_EXCLUSIVEADDRUSE, + SO_EXCLUSIVEADDRUSE, getprotobyname, getservbyname, getservbyport, getsockopt, + setsockopt, }; pub use winapi::um::ws2tcpip::{ EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NODATA, EAI_NONAME, EAI_SERVICE, EAI_SOCKTYPE, }; pub use windows_sys::Win32::Networking::WinSock::{ - AF_DECnet, AF_APPLETALK, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME, - AI_NUMERICSERV, AI_V4MAPPED, IPPORT_RESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, - IPPROTO_ESP, IPPROTO_FRAGMENT, IPPROTO_GGP, IPPROTO_HOPOPTS, IPPROTO_ICMP, - IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP, - IPPROTO_IPV4, IPPROTO_IPV6, IPPROTO_ND, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP, - IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_UDP, IPV6_CHECKSUM, IPV6_DONTFRAG, - IPV6_HOPLIMIT, IPV6_HOPOPTS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS, + AF_APPLETALK, AF_DECnet, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME, + AI_NUMERICSERV, AI_V4MAPPED, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_HDRINCL, + IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_OPTIONS, IP_RECVDSTADDR, + IP_TOS, IP_TTL, IPPORT_RESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, + IPPROTO_FRAGMENT, IPPROTO_GGP, IPPROTO_HOPOPTS, IPPROTO_ICMP, IPPROTO_ICMPV6, + IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP, IPPROTO_IPV4, + IPPROTO_IPV6, IPPROTO_ND, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, + IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_UDP, IPV6_CHECKSUM, IPV6_DONTFRAG, IPV6_HOPLIMIT, + IPV6_HOPOPTS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_PKTINFO, IPV6_RECVRTHDR, IPV6_RECVTCLASS, - IPV6_RTHDR, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, - IP_DROP_MEMBERSHIP, IP_HDRINCL, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, - IP_OPTIONS, IP_RECVDSTADDR, IP_TOS, IP_TTL, MSG_BCAST, MSG_CTRUNC, MSG_DONTROUTE, - MSG_MCAST, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_MAXSERV, - NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, RCVALL_IPLEVEL, RCVALL_OFF, - RCVALL_ON, RCVALL_SOCKETLEVELONLY, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD, - SD_SEND as SHUT_WR, SIO_KEEPALIVE_VALS, SIO_LOOPBACK_FAST_PATH, SIO_RCVALL, SOCK_DGRAM, - SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SOMAXCONN, SO_BROADCAST, - SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, SO_USELOOPBACK, TCP_NODELAY, - WSAEBADF, WSAECONNRESET, WSAENOTSOCK, WSAEWOULDBLOCK, + IPV6_RTHDR, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, MSG_BCAST, MSG_CTRUNC, + MSG_DONTROUTE, MSG_MCAST, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, + NI_MAXHOST, NI_MAXSERV, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, + RCVALL_IPLEVEL, RCVALL_OFF, RCVALL_ON, RCVALL_SOCKETLEVELONLY, SD_BOTH as SHUT_RDWR, + SD_RECEIVE as SHUT_RD, SD_SEND as SHUT_WR, SIO_KEEPALIVE_VALS, SIO_LOOPBACK_FAST_PATH, + SIO_RCVALL, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, + SO_USELOOPBACK, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, + SOL_SOCKET, SOMAXCONN, TCP_NODELAY, WSAEBADF, WSAECONNRESET, WSAENOTSOCK, + WSAEWOULDBLOCK, }; pub const IF_NAMESIZE: usize = windows_sys::Win32::NetworkManagement::Ndis::IF_MAX_STRING_SIZE as _; @@ -86,14 +87,14 @@ mod _socket { IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, - SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, - SO_REUSEADDR, SO_TYPE, TCP_NODELAY, + SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, SOCK_DGRAM, + SOCK_STREAM, SOL_SOCKET, TCP_NODELAY, }; #[cfg(not(target_os = "redox"))] #[pyattr] use c::{ - AF_DECnet, AF_APPLETALK, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, + AF_APPLETALK, AF_DECnet, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, IPPROTO_FRAGMENT, IPPROTO_HOPOPTS, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IPIP, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING, }; @@ -126,8 +127,9 @@ mod _socket { J1939_IDLE_ADDR, J1939_MAX_UNICAST_ADDR, J1939_NLA_BYTES_ACKED, J1939_NLA_PAD, J1939_NO_ADDR, J1939_NO_NAME, J1939_NO_PGN, J1939_PGN_ADDRESS_CLAIMED, J1939_PGN_ADDRESS_COMMANDED, J1939_PGN_MAX, J1939_PGN_PDU1_MAX, J1939_PGN_REQUEST, - SCM_J1939_DEST_ADDR, SCM_J1939_DEST_NAME, SCM_J1939_ERRQUEUE, SCM_J1939_PRIO, SOL_CAN_BASE, - SOL_CAN_RAW, SO_J1939_ERRQUEUE, SO_J1939_FILTER, SO_J1939_PROMISC, SO_J1939_SEND_PRIO, + SCM_J1939_DEST_ADDR, SCM_J1939_DEST_NAME, SCM_J1939_ERRQUEUE, SCM_J1939_PRIO, + SO_J1939_ERRQUEUE, SO_J1939_FILTER, SO_J1939_PROMISC, SO_J1939_SEND_PRIO, SOL_CAN_BASE, + SOL_CAN_RAW, }; #[cfg(all(target_os = "linux", target_env = "gnu"))] @@ -168,11 +170,11 @@ mod _socket { #[pyattr] use c::{ ALG_OP_DECRYPT, ALG_OP_ENCRYPT, ALG_SET_AEAD_ASSOCLEN, ALG_SET_AEAD_AUTHSIZE, ALG_SET_IV, - ALG_SET_KEY, ALG_SET_OP, IPV6_DSTOPTS, IPV6_NEXTHOP, IPV6_PATHMTU, IPV6_RECVDSTOPTS, - IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS, IPV6_RECVPATHMTU, IPV6_RTHDRDSTOPTS, - IP_DEFAULT_MULTICAST_LOOP, IP_RECVOPTS, IP_RETOPTS, NETLINK_CRYPTO, NETLINK_DNRTMSG, - NETLINK_FIREWALL, NETLINK_IP6_FW, NETLINK_NFLOG, NETLINK_ROUTE, NETLINK_USERSOCK, - NETLINK_XFRM, SOL_ALG, SO_PASSSEC, SO_PEERSEC, + ALG_SET_KEY, ALG_SET_OP, IP_DEFAULT_MULTICAST_LOOP, IP_RECVOPTS, IP_RETOPTS, IPV6_DSTOPTS, + IPV6_NEXTHOP, IPV6_PATHMTU, IPV6_RECVDSTOPTS, IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS, + IPV6_RECVPATHMTU, IPV6_RTHDRDSTOPTS, NETLINK_CRYPTO, NETLINK_DNRTMSG, NETLINK_FIREWALL, + NETLINK_IP6_FW, NETLINK_NFLOG, NETLINK_ROUTE, NETLINK_USERSOCK, NETLINK_XFRM, SO_PASSSEC, + SO_PEERSEC, SOL_ALG, }; #[cfg(any(target_os = "android", target_vendor = "apple"))] @@ -190,9 +192,9 @@ mod _socket { #[cfg(any(unix, target_os = "android", windows))] #[pyattr] use c::{ - INADDR_BROADCAST, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, - IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, - IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, + INADDR_BROADCAST, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, + IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, + IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, }; #[cfg(any(unix, target_os = "android", windows))] @@ -213,8 +215,8 @@ mod _socket { AF_ALG, AF_ASH, AF_ATMPVC, AF_ATMSVC, AF_AX25, AF_BRIDGE, AF_CAN, AF_ECONET, AF_IRDA, AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PPPOX, AF_RDS, AF_SECURITY, AF_TIPC, AF_VSOCK, AF_WANPIPE, AF_X25, IP_TRANSPARENT, MSG_CONFIRM, MSG_ERRQUEUE, - MSG_FASTOPEN, MSG_MORE, PF_CAN, PF_PACKET, PF_RDS, SCM_CREDENTIALS, SOL_IP, SOL_TIPC, - SOL_UDP, SO_BINDTODEVICE, SO_MARK, TCP_CORK, TCP_DEFER_ACCEPT, TCP_LINGER2, TCP_QUICKACK, + MSG_FASTOPEN, MSG_MORE, PF_CAN, PF_PACKET, PF_RDS, SCM_CREDENTIALS, SO_BINDTODEVICE, + SO_MARK, SOL_IP, SOL_TIPC, SOL_UDP, TCP_CORK, TCP_DEFER_ACCEPT, TCP_LINGER2, TCP_QUICKACK, TCP_SYNCNT, TCP_WINDOW_CLAMP, }; @@ -271,7 +273,7 @@ mod _socket { #[cfg(any(target_os = "android", target_os = "linux", windows))] #[pyattr] - use c::{IPV6_HOPOPTS, IPV6_RECVRTHDR, IPV6_RTHDR, IP_OPTIONS}; + use c::{IP_OPTIONS, IPV6_HOPOPTS, IPV6_RECVRTHDR, IPV6_RTHDR}; #[cfg(any( target_os = "dragonfly", @@ -525,7 +527,7 @@ mod _socket { ))] #[pyattr] use c::{ - AF_LINK, IPPROTO_GGP, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IP_RECVDSTADDR, SO_USELOOPBACK, + AF_LINK, IP_RECVDSTADDR, IPPROTO_GGP, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, SO_USELOOPBACK, }; #[cfg(any( @@ -633,7 +635,7 @@ mod _socket { #[pyattr] use c::{ EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NONAME, EAI_SERVICE, - EAI_SOCKTYPE, IPV6_RECVTCLASS, IPV6_TCLASS, IP_HDRINCL, IP_TOS, SOMAXCONN, + EAI_SOCKTYPE, IP_HDRINCL, IP_TOS, IPV6_RECVTCLASS, IPV6_TCLASS, SOMAXCONN, }; #[cfg(not(any( @@ -1473,11 +1475,7 @@ mod _socket { #[pymethod] fn gettimeout(&self) -> Option { let timeout = self.timeout.load(); - if timeout >= 0.0 { - Some(timeout) - } else { - None - } + if timeout >= 0.0 { Some(timeout) } else { None } } #[pymethod] @@ -1601,7 +1599,7 @@ mod _socket { _ => { return Err(vm .new_value_error("`how` must be SHUT_RD, SHUT_WR, or SHUT_RDWR".to_owned()) - .into()) + .into()); } }; Ok(self.sock()?.shutdown(how)?) @@ -2054,7 +2052,7 @@ mod _socket { _ => { return Err(vm .new_type_error("illegal sockaddr argument".to_owned()) - .into()) + .into()); } } let (addr, flowinfo, scopeid) = Address::from_tuple_ipv6(&address, vm)?; @@ -2259,7 +2257,7 @@ mod _socket { _ => { return Err(vm .new_os_error("address family mismatched".to_owned()) - .into()) + .into()); } } return Ok(SocketAddr::V4(net::SocketAddrV4::new( @@ -2433,11 +2431,7 @@ mod _socket { #[pyfunction] fn getdefaulttimeout() -> Option { let timeout = DEFAULT_TIMEOUT.load(); - if timeout >= 0.0 { - Some(timeout) - } else { - None - } + if timeout >= 0.0 { Some(timeout) } else { None } } #[pyfunction] diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index 9225ccbc50..5487511e20 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -8,7 +8,7 @@ // spell-checker:ignore cantlock commithook foreignkey notnull primarykey gettemppath autoindex convpath // spell-checker:ignore dbmoved vnode nbytes -use rustpython_vm::{builtins::PyModule, AsObject, PyRef, VirtualMachine}; +use rustpython_vm::{AsObject, PyRef, VirtualMachine, builtins::PyModule}; // pub(crate) use _sqlite::make_module; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { @@ -21,29 +21,29 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule] mod _sqlite { use libsqlite3_sys::{ - sqlite3, sqlite3_aggregate_context, sqlite3_backup_finish, sqlite3_backup_init, - sqlite3_backup_pagecount, sqlite3_backup_remaining, sqlite3_backup_step, sqlite3_bind_blob, - sqlite3_bind_double, sqlite3_bind_int64, sqlite3_bind_null, sqlite3_bind_parameter_count, - sqlite3_bind_parameter_name, sqlite3_bind_text, sqlite3_blob, sqlite3_blob_bytes, - sqlite3_blob_close, sqlite3_blob_open, sqlite3_blob_read, sqlite3_blob_write, - sqlite3_busy_timeout, sqlite3_changes, sqlite3_close_v2, sqlite3_column_blob, - sqlite3_column_bytes, sqlite3_column_count, sqlite3_column_decltype, sqlite3_column_double, - sqlite3_column_int64, sqlite3_column_name, sqlite3_column_text, sqlite3_column_type, - sqlite3_complete, sqlite3_context, sqlite3_context_db_handle, sqlite3_create_collation_v2, - sqlite3_create_function_v2, sqlite3_create_window_function, sqlite3_data_count, - sqlite3_db_handle, sqlite3_errcode, sqlite3_errmsg, sqlite3_exec, sqlite3_expanded_sql, - sqlite3_extended_errcode, sqlite3_finalize, sqlite3_get_autocommit, sqlite3_interrupt, - sqlite3_last_insert_rowid, sqlite3_libversion, sqlite3_limit, sqlite3_open_v2, - sqlite3_prepare_v2, sqlite3_progress_handler, sqlite3_reset, sqlite3_result_blob, - sqlite3_result_double, sqlite3_result_error, sqlite3_result_error_nomem, - sqlite3_result_error_toobig, sqlite3_result_int64, sqlite3_result_null, - sqlite3_result_text, sqlite3_set_authorizer, sqlite3_sleep, sqlite3_step, sqlite3_stmt, - sqlite3_stmt_busy, sqlite3_stmt_readonly, sqlite3_threadsafe, sqlite3_total_changes, - sqlite3_trace_v2, sqlite3_user_data, sqlite3_value, sqlite3_value_blob, - sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_int64, sqlite3_value_text, - sqlite3_value_type, SQLITE_BLOB, SQLITE_DETERMINISTIC, SQLITE_FLOAT, SQLITE_INTEGER, - SQLITE_NULL, SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_URI, SQLITE_TEXT, - SQLITE_TRACE_STMT, SQLITE_TRANSIENT, SQLITE_UTF8, + SQLITE_BLOB, SQLITE_DETERMINISTIC, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, + SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_URI, SQLITE_TEXT, SQLITE_TRACE_STMT, + SQLITE_TRANSIENT, SQLITE_UTF8, sqlite3, sqlite3_aggregate_context, sqlite3_backup_finish, + sqlite3_backup_init, sqlite3_backup_pagecount, sqlite3_backup_remaining, + sqlite3_backup_step, sqlite3_bind_blob, sqlite3_bind_double, sqlite3_bind_int64, + sqlite3_bind_null, sqlite3_bind_parameter_count, sqlite3_bind_parameter_name, + sqlite3_bind_text, sqlite3_blob, sqlite3_blob_bytes, sqlite3_blob_close, sqlite3_blob_open, + sqlite3_blob_read, sqlite3_blob_write, sqlite3_busy_timeout, sqlite3_changes, + sqlite3_close_v2, sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_count, + sqlite3_column_decltype, sqlite3_column_double, sqlite3_column_int64, sqlite3_column_name, + sqlite3_column_text, sqlite3_column_type, sqlite3_complete, sqlite3_context, + sqlite3_context_db_handle, sqlite3_create_collation_v2, sqlite3_create_function_v2, + sqlite3_create_window_function, sqlite3_data_count, sqlite3_db_handle, sqlite3_errcode, + sqlite3_errmsg, sqlite3_exec, sqlite3_expanded_sql, sqlite3_extended_errcode, + sqlite3_finalize, sqlite3_get_autocommit, sqlite3_interrupt, sqlite3_last_insert_rowid, + sqlite3_libversion, sqlite3_limit, sqlite3_open_v2, sqlite3_prepare_v2, + sqlite3_progress_handler, sqlite3_reset, sqlite3_result_blob, sqlite3_result_double, + sqlite3_result_error, sqlite3_result_error_nomem, sqlite3_result_error_toobig, + sqlite3_result_int64, sqlite3_result_null, sqlite3_result_text, sqlite3_set_authorizer, + sqlite3_sleep, sqlite3_step, sqlite3_stmt, sqlite3_stmt_busy, sqlite3_stmt_readonly, + sqlite3_threadsafe, sqlite3_total_changes, sqlite3_trace_v2, sqlite3_user_data, + sqlite3_value, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, + sqlite3_value_int64, sqlite3_value_text, sqlite3_value_type, }; use malachite_bigint::Sign; use rustpython_common::{ @@ -53,13 +53,16 @@ mod _sqlite { static_cell, }; use rustpython_vm::{ - atomic_func, + __exports::paste, + AsObject, Py, PyAtomicRef, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, VirtualMachine, atomic_func, builtins::{ PyBaseException, PyBaseExceptionRef, PyByteArray, PyBytes, PyDict, PyDictRef, PyFloat, PyInt, PyIntRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, }, convert::IntoObject, function::{ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue}, + object::{Traverse, TraverseFn}, protocol::{PyBuffer, PyIterReturn, PyMappingMethods, PySequence, PySequenceMethods}, sliceable::{SaturatedSliceIter, SliceableSequenceOp}, types::{ @@ -67,16 +70,12 @@ mod _sqlite { PyComparisonOp, SelfIter, }, utils::ToCString, - AsObject, Py, PyAtomicRef, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, VirtualMachine, - __exports::paste, - object::{Traverse, TraverseFn}, }; use std::{ - ffi::{c_int, c_longlong, c_uint, c_void, CStr}, + ffi::{CStr, c_int, c_longlong, c_uint, c_void}, fmt::Debug, ops::Deref, - ptr::{null, null_mut, NonNull}, + ptr::{NonNull, null, null_mut}, thread::ThreadId, }; @@ -445,7 +444,7 @@ mod _sqlite { vm, exc, "user-defined aggregate's '__init__' method raised error\0", - ) + ); } } } @@ -2082,7 +2081,7 @@ mod _sqlite { _ => { return Err(vm.new_value_error( "'origin' should be os.SEEK_SET, os.SEEK_CUR, or os.SEEK_END".to_owned(), - )) + )); } } diff --git a/stdlib/src/ssl.rs b/stdlib/src/ssl.rs index e90f08f2ef..2b8ffc7d8c 100644 --- a/stdlib/src/ssl.rs +++ b/stdlib/src/ssl.rs @@ -1,4 +1,4 @@ -use crate::vm::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::vm::{PyRef, VirtualMachine, builtins::PyModule}; use openssl_probe::ProbeResult; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { @@ -36,6 +36,7 @@ mod _ssl { }, socket::{self, PySocket}, vm::{ + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef, PyWeak}, convert::{ToPyException, ToPyObject}, exceptions, @@ -45,7 +46,6 @@ mod _ssl { }, types::Constructor, utils::ToCString, - PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }, }; use crossbeam_utils::atomic::AtomicCell; @@ -55,7 +55,7 @@ mod _ssl { error::ErrorStack, nid::Nid, ssl::{self, SslContextBuilder, SslOptions, SslVerifyMode}, - x509::{self, X509Ref, X509}, + x509::{self, X509, X509Ref}, }; use openssl_sys as sys; use rustpython_vm::ospath::OsPath; @@ -70,9 +70,6 @@ mod _ssl { // Constants #[pyattr] use sys::{ - SSL_OP_NO_SSLv2 as OP_NO_SSLv2, - SSL_OP_NO_SSLv3 as OP_NO_SSLv3, - SSL_OP_NO_TLSv1 as OP_NO_TLSv1, // TODO: so many more of these SSL_AD_DECODE_ERROR as ALERT_DESCRIPTION_DECODE_ERROR, SSL_AD_ILLEGAL_PARAMETER as ALERT_DESCRIPTION_ILLEGAL_PARAMETER, @@ -92,7 +89,10 @@ mod _ssl { // X509_V_FLAG_X509_STRICT as VERIFY_X509_STRICT, SSL_ERROR_ZERO_RETURN, SSL_OP_CIPHER_SERVER_PREFERENCE as OP_CIPHER_SERVER_PREFERENCE, + SSL_OP_NO_SSLv2 as OP_NO_SSLv2, + SSL_OP_NO_SSLv3 as OP_NO_SSLv3, SSL_OP_NO_TICKET as OP_NO_TICKET, + SSL_OP_NO_TLSv1 as OP_NO_TLSv1, SSL_OP_SINGLE_DH_USE as OP_SINGLE_DH_USE, }; @@ -601,7 +601,7 @@ mod _ssl { return Err(vm.new_value_error( "Cannot set verify_mode to CERT_NONE when check_hostname is enabled." .to_owned(), - )) + )); } CertRequirements::None => SslVerifyMode::NONE, CertRequirements::Optional => SslVerifyMode::PEER, @@ -1006,11 +1006,7 @@ mod _ssl { #[pymethod] fn version(&self) -> Option<&'static str> { let v = self.stream.read().ssl().version_str(); - if v == "unknown" { - None - } else { - Some(v) - } + if v == "unknown" { None } else { Some(v) } } #[pymethod] @@ -1058,7 +1054,7 @@ mod _ssl { return Err(socket::timeout_error_msg( vm, "The handshake operation timed out".to_owned(), - )) + )); } SelectRet::Closed => return Err(socket_closed_error(vm)), SelectRet::Nonblocking => {} @@ -1084,7 +1080,7 @@ mod _ssl { return Err(socket::timeout_error_msg( vm, "The write operation timed out".to_owned(), - )) + )); } SelectRet::Closed => return Err(socket_closed_error(vm)), _ => {} @@ -1100,7 +1096,7 @@ mod _ssl { return Err(socket::timeout_error_msg( vm, "The write operation timed out".to_owned(), - )) + )); } SelectRet::Closed => return Err(socket_closed_error(vm)), SelectRet::Nonblocking => {} @@ -1152,7 +1148,7 @@ mod _ssl { return Err(socket::timeout_error_msg( vm, "The read operation timed out".to_owned(), - )) + )); } SelectRet::Nonblocking => {} _ => { @@ -1385,13 +1381,13 @@ mod _ssl { #[cfg(target_os = "android")] mod android { use super::convert_openssl_error; - use crate::vm::{builtins::PyBaseExceptionRef, VirtualMachine}; + use crate::vm::{VirtualMachine, builtins::PyBaseExceptionRef}; use openssl::{ ssl::SslContextBuilder, - x509::{store::X509StoreBuilder, X509}, + x509::{X509, store::X509StoreBuilder}, }; use std::{ - fs::{read_dir, File}, + fs::{File, read_dir}, io::Read, path::Path, }; @@ -1465,8 +1461,8 @@ mod windows {} mod ossl101 { #[pyattr] use openssl_sys::{ - SSL_OP_NO_TLSv1_1 as OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2 as OP_NO_TLSv1_2, - SSL_OP_NO_COMPRESSION as OP_NO_COMPRESSION, + SSL_OP_NO_COMPRESSION as OP_NO_COMPRESSION, SSL_OP_NO_TLSv1_1 as OP_NO_TLSv1_1, + SSL_OP_NO_TLSv1_2 as OP_NO_TLSv1_2, }; } @@ -1484,15 +1480,15 @@ mod windows { use crate::{ common::ascii, vm::{ + PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyFrozenSet, PyStrRef}, convert::ToPyException, - PyObjectRef, PyPayload, PyResult, VirtualMachine, }, }; #[pyfunction] fn enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult> { - use schannel::{cert_context::ValidUses, cert_store::CertStore, RawPointer}; + use schannel::{RawPointer, cert_context::ValidUses, cert_store::CertStore}; use windows_sys::Win32::Security::Cryptography; // TODO: check every store for it, not just 2 of them: diff --git a/stdlib/src/statistics.rs b/stdlib/src/statistics.rs index 356bfd66f9..72e5d129a0 100644 --- a/stdlib/src/statistics.rs +++ b/stdlib/src/statistics.rs @@ -2,7 +2,7 @@ pub(crate) use _statistics::make_module; #[pymodule] mod _statistics { - use crate::vm::{function::ArgIntoFloat, PyResult, VirtualMachine}; + use crate::vm::{PyResult, VirtualMachine, function::ArgIntoFloat}; // See https://github.com/python/cpython/blob/6846d6712a0894f8e1a91716c11dd79f42864216/Modules/_statisticsmodule.c#L28-L120 #[allow(clippy::excessive_precision)] diff --git a/stdlib/src/syslog.rs b/stdlib/src/syslog.rs index 5fc6e30a56..3b36f9ea74 100644 --- a/stdlib/src/syslog.rs +++ b/stdlib/src/syslog.rs @@ -6,10 +6,10 @@ pub(crate) use syslog::make_module; mod syslog { use crate::common::lock::PyRwLock; use crate::vm::{ + PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyStr, PyStrRef}, function::{OptionalArg, OptionalOption}, utils::ToCString, - PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use std::{ffi::CStr, os::raw::c_char}; diff --git a/stdlib/src/termios.rs b/stdlib/src/termios.rs index 84c12b2b68..5c49d62a3c 100644 --- a/stdlib/src/termios.rs +++ b/stdlib/src/termios.rs @@ -3,10 +3,10 @@ pub(crate) use self::termios::make_module; #[pymodule] mod termios { use crate::vm::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytes, PyInt, PyListRef, PyTypeRef}, common::os::ErrorExt, convert::ToPyObject, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use termios::Termios; @@ -55,9 +55,9 @@ mod termios { ))] #[pyattr] use libc::{ - FIONCLEX, FIONREAD, TIOCEXCL, TIOCMBIC, TIOCMBIS, TIOCMGET, TIOCMSET, TIOCM_CAR, TIOCM_CD, - TIOCM_CTS, TIOCM_DSR, TIOCM_DTR, TIOCM_LE, TIOCM_RI, TIOCM_RNG, TIOCM_RTS, TIOCM_SR, - TIOCM_ST, TIOCNXCL, TIOCSCTTY, + FIONCLEX, FIONREAD, TIOCEXCL, TIOCM_CAR, TIOCM_CD, TIOCM_CTS, TIOCM_DSR, TIOCM_DTR, + TIOCM_LE, TIOCM_RI, TIOCM_RNG, TIOCM_RTS, TIOCM_SR, TIOCM_ST, TIOCMBIC, TIOCMBIS, TIOCMGET, + TIOCMSET, TIOCNXCL, TIOCSCTTY, }; #[cfg(any(target_os = "android", target_os = "linux"))] #[pyattr] @@ -100,12 +100,6 @@ mod termios { ))] #[pyattr] use termios::os::target::TCSASOFT; - #[cfg(any(target_os = "android", target_os = "linux"))] - #[pyattr] - use termios::os::target::{ - B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000, B500000, - B576000, CBAUDEX, - }; #[cfg(any( target_os = "android", target_os = "freebsd", @@ -116,6 +110,12 @@ mod termios { ))] #[pyattr] use termios::os::target::{B460800, B921600}; + #[cfg(any(target_os = "android", target_os = "linux"))] + #[pyattr] + use termios::os::target::{ + B500000, B576000, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, + B4000000, CBAUDEX, + }; #[cfg(any( target_os = "android", target_os = "illumos", @@ -154,16 +154,17 @@ mod termios { use termios::os::target::{VSWTCH, VSWTCH as VSWTC}; #[pyattr] use termios::{ + B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600, + B19200, B38400, BRKINT, CLOCAL, CREAD, CS5, CS6, CS7, CS8, CSIZE, CSTOPB, ECHO, ECHOE, + ECHOK, ECHONL, HUPCL, ICANON, ICRNL, IEXTEN, IGNBRK, IGNCR, IGNPAR, INLCR, INPCK, ISIG, + ISTRIP, IXANY, IXOFF, IXON, NOFLSH, OCRNL, ONLCR, ONLRET, ONOCR, OPOST, PARENB, PARMRK, + PARODD, TCIFLUSH, TCIOFF, TCIOFLUSH, TCION, TCOFLUSH, TCOOFF, TCOON, TCSADRAIN, TCSAFLUSH, + TCSANOW, TOSTOP, VEOF, VEOL, VERASE, VINTR, VKILL, VMIN, VQUIT, VSTART, VSTOP, VSUSP, + VTIME, os::target::{ - B115200, B230400, B57600, CRTSCTS, ECHOCTL, ECHOKE, ECHOPRT, EXTA, EXTB, FLUSHO, + B57600, B115200, B230400, CRTSCTS, ECHOCTL, ECHOKE, ECHOPRT, EXTA, EXTB, FLUSHO, IMAXBEL, NCCS, PENDIN, VDISCARD, VEOL2, VLNEXT, VREPRINT, VWERASE, }, - B0, B110, B1200, B134, B150, B1800, B19200, B200, B2400, B300, B38400, B4800, B50, B600, - B75, B9600, BRKINT, CLOCAL, CREAD, CS5, CS6, CS7, CS8, CSIZE, CSTOPB, ECHO, ECHOE, ECHOK, - ECHONL, HUPCL, ICANON, ICRNL, IEXTEN, IGNBRK, IGNCR, IGNPAR, INLCR, INPCK, ISIG, ISTRIP, - IXANY, IXOFF, IXON, NOFLSH, OCRNL, ONLCR, ONLRET, ONOCR, OPOST, PARENB, PARMRK, PARODD, - TCIFLUSH, TCIOFF, TCIOFLUSH, TCION, TCOFLUSH, TCOOFF, TCOON, TCSADRAIN, TCSAFLUSH, TCSANOW, - TOSTOP, VEOF, VEOL, VERASE, VINTR, VKILL, VMIN, VQUIT, VSTART, VSTOP, VSUSP, VTIME, }; #[pyfunction] diff --git a/stdlib/src/unicodedata.rs b/stdlib/src/unicodedata.rs index 70483073a7..49f3ef6250 100644 --- a/stdlib/src/unicodedata.rs +++ b/stdlib/src/unicodedata.rs @@ -5,8 +5,8 @@ // spell-checker:ignore nfkc unistr unidata use crate::vm::{ - builtins::PyModule, builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyObjectRef, - PyPayload, PyRef, PyResult, VirtualMachine, + PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyModule, + builtins::PyStr, convert::TryFromBorrowedObject, }; pub fn make_module(vm: &VirtualMachine) -> PyRef { @@ -61,14 +61,14 @@ impl<'a> TryFromBorrowedObject<'a> for NormalizeForm { #[pymodule] mod unicodedata { use crate::vm::{ - builtins::PyStrRef, function::OptionalArg, PyObjectRef, PyPayload, PyRef, PyResult, - VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyStrRef, + function::OptionalArg, }; use itertools::Itertools; use ucd::{Codepoint, EastAsianWidth}; use unic_char_property::EnumeratedCharProperty; use unic_normal::StrNormalForm; - use unic_ucd_age::{Age, UnicodeVersion, UNICODE_VERSION}; + use unic_ucd_age::{Age, UNICODE_VERSION, UnicodeVersion}; use unic_ucd_bidi::BidiClass; use unic_ucd_category::GeneralCategory; diff --git a/stdlib/src/uuid.rs b/stdlib/src/uuid.rs index 4cadbb787b..0bd7d0db8a 100644 --- a/stdlib/src/uuid.rs +++ b/stdlib/src/uuid.rs @@ -5,7 +5,7 @@ mod _uuid { use crate::{builtins::PyNone, vm::VirtualMachine}; use mac_address::get_mac_address; use once_cell::sync::OnceCell; - use uuid::{timestamp::Timestamp, Context, Uuid}; + use uuid::{Context, Uuid, timestamp::Timestamp}; fn get_node_id() -> [u8; 6] { match get_mac_address() { diff --git a/stdlib/src/zlib.rs b/stdlib/src/zlib.rs index bcfe93aff5..19ed659bbb 100644 --- a/stdlib/src/zlib.rs +++ b/stdlib/src/zlib.rs @@ -5,17 +5,17 @@ pub(crate) use zlib::make_module; #[pymodule] mod zlib { use crate::vm::{ + PyObject, PyPayload, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytesRef, PyIntRef, PyTypeRef}, common::lock::PyMutex, convert::TryFromBorrowedObject, function::{ArgBytesLike, ArgPrimitiveIndex, ArgSize, OptionalArg}, types::Constructor, - PyObject, PyPayload, PyResult, VirtualMachine, }; use adler32::RollingAdler32 as Adler32; use flate2::{ - write::ZlibEncoder, Compress, Compression, Decompress, FlushCompress, FlushDecompress, - Status, + Compress, Compression, Decompress, FlushCompress, FlushDecompress, Status, + write::ZlibEncoder, }; use std::io::Write; @@ -420,7 +420,7 @@ mod zlib { fn flush(&self, length: OptionalArg, vm: &VirtualMachine) -> PyResult> { let length = match length { OptionalArg::Present(ArgSize { value }) if value <= 0 => { - return Err(vm.new_value_error("length must be greater than zero".to_owned())) + return Err(vm.new_value_error("length must be greater than zero".to_owned())); } OptionalArg::Present(ArgSize { value }) => value as usize, OptionalArg::Missing => DEF_BUF_SIZE, diff --git a/vm/src/anystr.rs b/vm/src/anystr.rs index f5bfab1c57..0fd1d8f2f6 100644 --- a/vm/src/anystr.rs +++ b/vm/src/anystr.rs @@ -1,9 +1,9 @@ use crate::{ + Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyIntRef, PyTuple}, cformat::cformat_string, convert::TryFromBorrowedObject, function::OptionalOption, - Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use num_traits::{cast::ToPrimitive, sign::Signed}; @@ -386,11 +386,7 @@ pub trait AnyStr { b'\n' => (keep, 1), b'\r' => { let is_rn = enumerated.next_if(|(_, ch)| **ch == b'\n').is_some(); - if is_rn { - (keep + keep, 2) - } else { - (keep, 1) - } + if is_rn { (keep + keep, 2) } else { (keep, 1) } } _ => continue, }; diff --git a/vm/src/buffer.rs b/vm/src/buffer.rs index bebc7b13a9..3b76002d04 100644 --- a/vm/src/buffer.rs +++ b/vm/src/buffer.rs @@ -1,9 +1,9 @@ use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytesRef, PyTuple, PyTupleRef, PyTypeRef}, common::{static_cell, str::wchar_t}, convert::ToPyObject, function::{ArgBytesLike, ArgIntoBool, ArgIntoFloat}, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use half::f16; use itertools::Itertools; @@ -99,8 +99,8 @@ impl fmt::Debug for FormatType { impl FormatType { fn info(self, e: Endianness) -> &'static FormatInfo { - use mem::{align_of, size_of}; use FormatType::*; + use mem::{align_of, size_of}; macro_rules! native_info { ($t:ty) => {{ &FormatInfo { diff --git a/vm/src/builtins/asyncgenerator.rs b/vm/src/builtins/asyncgenerator.rs index f9ed4719d8..3aee327e5b 100644 --- a/vm/src/builtins/asyncgenerator.rs +++ b/vm/src/builtins/asyncgenerator.rs @@ -1,5 +1,6 @@ use super::{PyCode, PyGenericAlias, PyStrRef, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyBaseExceptionRef, class::PyClassImpl, coroutine::Coro, @@ -7,7 +8,6 @@ use crate::{ function::OptionalArg, protocol::PyIterReturn, types::{IterNext, Iterable, Representable, SelfIter, Unconstructible}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; @@ -208,7 +208,7 @@ impl PyAsyncGenASend { AwaitableState::Closed => { return Err(vm.new_runtime_error( "cannot reuse already awaited __anext__()/asend()".to_owned(), - )) + )); } AwaitableState::Iter => val, // already running, all good AwaitableState::Init => { diff --git a/vm/src/builtins/bool.rs b/vm/src/builtins/bool.rs index 63bf6cff2d..93f5f4f1de 100644 --- a/vm/src/builtins/bool.rs +++ b/vm/src/builtins/bool.rs @@ -1,13 +1,13 @@ use super::{PyInt, PyStrRef, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, + VirtualMachine, class::PyClassImpl, convert::{IntoPyException, ToPyObject, ToPyResult}, function::OptionalArg, identifier, protocol::PyNumberMethods, types::{AsNumber, Constructor, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, - VirtualMachine, }; use malachite_bigint::Sign; use num_traits::Zero; diff --git a/vm/src/builtins/builtin_func.rs b/vm/src/builtins/builtin_func.rs index bc1b082bc9..ff3ef38d3a 100644 --- a/vm/src/builtins/builtin_func.rs +++ b/vm/src/builtins/builtin_func.rs @@ -1,10 +1,10 @@ -use super::{type_, PyStrInterned, PyStrRef, PyType}; +use super::{PyStrInterned, PyStrRef, PyType, type_}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, convert::TryFromObject, function::{FuncArgs, PyComparisonValue, PyMethodDef, PyMethodFlags, PyNativeFn}, types::{Callable, Comparable, PyComparisonOp, Representable, Unconstructible}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use std::fmt; diff --git a/vm/src/builtins/bytearray.rs b/vm/src/builtins/bytearray.rs index 40e6cf7b5c..36cf8cadcd 100644 --- a/vm/src/builtins/bytearray.rs +++ b/vm/src/builtins/bytearray.rs @@ -4,12 +4,14 @@ use super::{ PyType, PyTypeRef, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, anystr::{self, AnyStr}, atomic_func, byte::{bytes_from_object, value_from_object}, bytesinner::{ - bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, - ByteInnerSplitOptions, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, + ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, ByteInnerSplitOptions, + ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, bytes_decode, }, class::PyClassImpl, common::{ @@ -33,8 +35,6 @@ use crate::{ DefaultConstructor, Initializer, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - VirtualMachine, }; use bstr::ByteSlice; use std::mem::size_of; diff --git a/vm/src/builtins/bytes.rs b/vm/src/builtins/bytes.rs index 1db6417836..e9f5adc8bb 100644 --- a/vm/src/builtins/bytes.rs +++ b/vm/src/builtins/bytes.rs @@ -2,11 +2,13 @@ use super::{ PositionIterInternal, PyDictRef, PyIntRef, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, TryFromObject, VirtualMachine, anystr::{self, AnyStr}, atomic_func, bytesinner::{ - bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, - ByteInnerSplitOptions, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, + ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, ByteInnerSplitOptions, + ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, bytes_decode, }, class::PyClassImpl, common::{hash::PyHash, lock::PyMutex}, @@ -23,8 +25,6 @@ use crate::{ AsBuffer, AsMapping, AsNumber, AsSequence, Callable, Comparable, Constructor, Hashable, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use bstr::ByteSlice; use once_cell::sync::Lazy; diff --git a/vm/src/builtins/classmethod.rs b/vm/src/builtins/classmethod.rs index 02f836199e..94b6e0ca9f 100644 --- a/vm/src/builtins/classmethod.rs +++ b/vm/src/builtins/classmethod.rs @@ -1,9 +1,9 @@ use super::{PyBoundMethod, PyStr, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, common::lock::PyMutex, types::{Constructor, GetDescriptor, Initializer, Representable}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; /// classmethod(function) -> method diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs index bedd71f241..d9d8895b19 100644 --- a/vm/src/builtins/code.rs +++ b/vm/src/builtins/code.rs @@ -4,6 +4,7 @@ use super::{PyStrRef, PyTupleRef, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::PyStrInterned, bytecode::{self, AsBag, BorrowedConstant, CodeFlags, Constant, ConstantBag}, class::{PyClassImpl, StaticType}, @@ -12,7 +13,6 @@ use crate::{ function::{FuncArgs, OptionalArg}, source_code::OneIndexed, types::Representable, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use malachite_bigint::BigInt; use num_traits::Zero; diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index fb5bc5066c..e665d1e27a 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -1,5 +1,6 @@ -use super::{float, PyStr, PyType, PyTypeRef}; +use super::{PyStr, PyType, PyTypeRef, float}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, convert::{ToPyObject, ToPyResult}, function::{ @@ -11,7 +12,6 @@ use crate::{ protocol::PyNumberMethods, stdlib::warnings, types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use num_complex::Complex64; use num_traits::Zero; diff --git a/vm/src/builtins/coroutine.rs b/vm/src/builtins/coroutine.rs index db9592bd47..cca2db3293 100644 --- a/vm/src/builtins/coroutine.rs +++ b/vm/src/builtins/coroutine.rs @@ -1,12 +1,12 @@ use super::{PyCode, PyStrRef, PyType}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, coroutine::Coro, frame::FrameRef, function::OptionalArg, protocol::PyIterReturn, types::{IterNext, Iterable, Representable, SelfIter, Unconstructible}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "coroutine")] diff --git a/vm/src/builtins/descriptor.rs b/vm/src/builtins/descriptor.rs index 4b10f63f21..9da4e1d87a 100644 --- a/vm/src/builtins/descriptor.rs +++ b/vm/src/builtins/descriptor.rs @@ -1,10 +1,10 @@ use super::{PyStr, PyStrInterned, PyType}; use crate::{ - builtins::{builtin_func::PyNativeMethod, type_, PyTypeRef}, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, + builtins::{PyTypeRef, builtin_func::PyNativeMethod, type_}, class::PyClassImpl, function::{FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue}, types::{Callable, GetDescriptor, Representable, Unconstructible}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use rustpython_common::lock::PyRwLock; diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index 68567e493f..e54d2a1931 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -1,13 +1,14 @@ use super::{ - set::PySetInner, IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, - PyMappingProxy, PySet, PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef, + IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, PyMappingProxy, PySet, + PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef, set::PySetInner, }; use crate::{ - atomic_func, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, + TryFromObject, atomic_func, builtins::{ + PyTuple, iter::{builtins_iter, builtins_reversed}, type_::PyAttributes, - PyTuple, }, class::{PyClassDef, PyClassImpl}, common::ascii, @@ -21,8 +22,6 @@ use crate::{ Initializer, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, vm::VirtualMachine, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, - TryFromObject, }; use once_cell::sync::Lazy; use rustpython_common::lock::PyMutex; diff --git a/vm/src/builtins/enumerate.rs b/vm/src/builtins/enumerate.rs index 64d7c1ed36..aa84115074 100644 --- a/vm/src/builtins/enumerate.rs +++ b/vm/src/builtins/enumerate.rs @@ -3,12 +3,12 @@ use super::{ }; use crate::common::lock::{PyMutex, PyRwLock}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, convert::ToPyObject, function::OptionalArg, protocol::{PyIter, PyIterReturn}, types::{Constructor, IterNext, Iterable, SelfIter}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use malachite_bigint::BigInt; use num_traits::Zero; diff --git a/vm/src/builtins/filter.rs b/vm/src/builtins/filter.rs index 3b33ff766f..009a1b3eab 100644 --- a/vm/src/builtins/filter.rs +++ b/vm/src/builtins/filter.rs @@ -1,9 +1,9 @@ use super::{PyType, PyTypeRef}; use crate::{ + Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, protocol::{PyIter, PyIterReturn}, types::{Constructor, IterNext, Iterable, SelfIter}, - Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "filter", traverse)] diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index 27fdff12ee..e33c25cb56 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -1,9 +1,11 @@ // spell-checker:ignore numer denom use super::{ - try_bigint_to_f64, PyByteArray, PyBytes, PyInt, PyIntRef, PyStr, PyStrRef, PyType, PyTypeRef, + PyByteArray, PyBytes, PyInt, PyIntRef, PyStr, PyStrRef, PyType, PyTypeRef, try_bigint_to_f64, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, TryFromObject, VirtualMachine, class::PyClassImpl, common::{float_ops, hash}, convert::{IntoPyException, ToPyObject, ToPyResult}, @@ -14,8 +16,6 @@ use crate::{ }, protocol::PyNumberMethods, types::{AsNumber, Callable, Comparable, Constructor, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use malachite_bigint::{BigInt, ToBigInt}; use num_complex::Complex64; diff --git a/vm/src/builtins/frame.rs b/vm/src/builtins/frame.rs index 3cc7d788fb..1fd031984a 100644 --- a/vm/src/builtins/frame.rs +++ b/vm/src/builtins/frame.rs @@ -4,11 +4,11 @@ use super::{PyCode, PyDictRef, PyIntRef, PyStrRef}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyRef, PyResult, VirtualMachine, class::PyClassImpl, frame::{Frame, FrameRef}, function::PySetterValue, types::{Representable, Unconstructible}, - AsObject, Context, Py, PyObjectRef, PyRef, PyResult, VirtualMachine, }; use num_traits::Zero; diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index eb5a142f0c..63cf8ac5c3 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -2,8 +2,8 @@ mod jitfunc; use super::{ - tuple::PyTupleTyped, PyAsyncGen, PyCode, PyCoroutine, PyDictRef, PyGenerator, PyStr, PyStrRef, - PyTupleRef, PyType, PyTypeRef, + PyAsyncGen, PyCode, PyCoroutine, PyDictRef, PyGenerator, PyStr, PyStrRef, PyTupleRef, PyType, + PyTypeRef, tuple::PyTupleTyped, }; #[cfg(feature = "jit")] use crate::common::lock::OnceCell; @@ -12,6 +12,7 @@ use crate::convert::ToPyObject; use crate::function::ArgMapping; use crate::object::{Traverse, TraverseFn}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, bytecode, class::PyClassImpl, frame::Frame, @@ -20,7 +21,6 @@ use crate::{ types::{ Callable, Comparable, Constructor, GetAttr, GetDescriptor, PyComparisonOp, Representable, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use itertools::Itertools; #[cfg(feature = "jit")] diff --git a/vm/src/builtins/function/jitfunc.rs b/vm/src/builtins/function/jitfunc.rs index d46458fc65..a46d9aa0f3 100644 --- a/vm/src/builtins/function/jitfunc.rs +++ b/vm/src/builtins/function/jitfunc.rs @@ -1,9 +1,9 @@ use crate::{ - builtins::{bool_, float, int, PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned}, + AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, + builtins::{PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned, bool_, float, int}, bytecode::CodeFlags, convert::ToPyObject, function::FuncArgs, - AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use num_traits::ToPrimitive; use rustpython_jit::{AbiValue, Args, CompiledCode, JitArgumentError, JitType}; diff --git a/vm/src/builtins/generator.rs b/vm/src/builtins/generator.rs index e0ec77006d..db9c263cb2 100644 --- a/vm/src/builtins/generator.rs +++ b/vm/src/builtins/generator.rs @@ -4,13 +4,13 @@ use super::{PyCode, PyStrRef, PyType}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, coroutine::Coro, frame::FrameRef, function::OptionalArg, protocol::PyIterReturn, types::{IterNext, Iterable, Representable, SelfIter, Unconstructible}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "generator")] diff --git a/vm/src/builtins/genericalias.rs b/vm/src/builtins/genericalias.rs index 2746b03128..57c97ba62b 100644 --- a/vm/src/builtins/genericalias.rs +++ b/vm/src/builtins/genericalias.rs @@ -2,7 +2,8 @@ use once_cell::sync::Lazy; use super::type_; use crate::{ - atomic_func, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, atomic_func, builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyType, PyTypeRef}, class::PyClassImpl, common::hash, @@ -13,8 +14,6 @@ use crate::{ AsMapping, AsNumber, Callable, Comparable, Constructor, GetAttr, Hashable, PyComparisonOp, Representable, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - VirtualMachine, }; use std::fmt; diff --git a/vm/src/builtins/getset.rs b/vm/src/builtins/getset.rs index 603ec021e2..c2e11b770a 100644 --- a/vm/src/builtins/getset.rs +++ b/vm/src/builtins/getset.rs @@ -3,10 +3,10 @@ */ use super::{PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, function::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc, PySetterValue}, types::{GetDescriptor, Unconstructible}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "getset_descriptor")] diff --git a/vm/src/builtins/int.rs b/vm/src/builtins/int.rs index eb05b4394a..db9c5ea4ed 100644 --- a/vm/src/builtins/int.rs +++ b/vm/src/builtins/int.rs @@ -1,5 +1,7 @@ -use super::{float, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef}; +use super::{PyByteArray, PyBytes, PyStr, PyType, PyTypeRef, float}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, + TryFromBorrowedObject, VirtualMachine, builtins::PyStrRef, bytesinner::PyBytesInner, class::PyClassImpl, @@ -14,8 +16,6 @@ use crate::{ }, protocol::PyNumberMethods, types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, - TryFromBorrowedObject, VirtualMachine, }; use malachite_bigint::{BigInt, Sign}; use num_integer::Integer; @@ -109,11 +109,7 @@ fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult { } else if int1.is_zero() { 0 } else if int1 == &BigInt::from(-1) { - if int2.is_odd() { - -1 - } else { - 1 - } + if int2.is_odd() { -1 } else { 1 } } else { // missing feature: BigInt exp // practically, exp over u64 is not possible to calculate anyway @@ -426,11 +422,7 @@ impl PyInt { // based on rust-num/num-integer#10, should hopefully be published soon fn normalize(a: BigInt, n: &BigInt) -> BigInt { let a = a % n; - if a.is_negative() { - a + n - } else { - a - } + if a.is_negative() { a + n } else { a } } fn inverse(a: BigInt, n: &BigInt) -> Option { use num_integer::*; @@ -642,7 +634,7 @@ impl PyInt { Sign::Minus if !signed => { return Err( vm.new_overflow_error("can't convert negative int to unsigned".to_owned()) - ) + ); } Sign::NoSign => return Ok(vec![0u8; byte_len].into()), _ => {} diff --git a/vm/src/builtins/iter.rs b/vm/src/builtins/iter.rs index dbe4fc6597..5a47abfac7 100644 --- a/vm/src/builtins/iter.rs +++ b/vm/src/builtins/iter.rs @@ -4,12 +4,12 @@ use super::{PyInt, PyTupleRef, PyType}; use crate::{ + Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, function::ArgCallable, object::{Traverse, TraverseFn}, protocol::{PyIterReturn, PySequence, PySequenceMethods}, types::{IterNext, Iterable, SelfIter}, - Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use rustpython_common::{ lock::{PyMutex, PyRwLock, PyRwLockUpgradableReadGuard}, diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index 33d6072cd5..3b9624694e 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -4,6 +4,7 @@ use crate::common::lock::{ PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, class::PyClassImpl, convert::ToPyObject, function::{ArgSize, FuncArgs, OptionalArg, PyComparisonValue}, @@ -18,7 +19,6 @@ use crate::{ }, utils::collection_repr, vm::VirtualMachine, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, }; use std::{fmt, ops::DerefMut}; diff --git a/vm/src/builtins/map.rs b/vm/src/builtins/map.rs index 44bacf587e..555e38c8b9 100644 --- a/vm/src/builtins/map.rs +++ b/vm/src/builtins/map.rs @@ -1,11 +1,11 @@ use super::{PyType, PyTypeRef}; use crate::{ + Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::PyTupleRef, class::PyClassImpl, function::PosArgs, protocol::{PyIter, PyIterReturn}, types::{Constructor, IterNext, Iterable, SelfIter}, - Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "map", traverse)] diff --git a/vm/src/builtins/mappingproxy.rs b/vm/src/builtins/mappingproxy.rs index 297ddd0a77..659562cec1 100644 --- a/vm/src/builtins/mappingproxy.rs +++ b/vm/src/builtins/mappingproxy.rs @@ -1,5 +1,6 @@ use super::{PyDict, PyDictRef, PyGenericAlias, PyList, PyTuple, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, class::PyClassImpl, convert::ToPyObject, @@ -10,7 +11,6 @@ use crate::{ AsMapping, AsNumber, AsSequence, Comparable, Constructor, Iterable, PyComparisonOp, Representable, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use once_cell::sync::Lazy; diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index dfbbdc5aaf..9426730f40 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -3,7 +3,8 @@ use super::{ PyTupleRef, PyType, PyTypeRef, }; use crate::{ - atomic_func, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, TryFromObject, VirtualMachine, atomic_func, buffer::FormatSpec, bytesinner::bytes_to_hex, class::PyClassImpl, @@ -24,8 +25,6 @@ use crate::{ AsBuffer, AsMapping, AsSequence, Comparable, Constructor, Hashable, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; @@ -223,14 +222,16 @@ impl PyMemoryView { fn pos_from_multi_index(&self, indexes: &[isize], vm: &VirtualMachine) -> PyResult { match indexes.len().cmp(&self.desc.ndim()) { Ordering::Less => { - return Err(vm.new_not_implemented_error("sub-views are not implemented".to_owned())) + return Err( + vm.new_not_implemented_error("sub-views are not implemented".to_owned()) + ); } Ordering::Greater => { return Err(vm.new_type_error(format!( "cannot index {}-dimension view with {}-element tuple", self.desc.ndim(), indexes.len() - ))) + ))); } Ordering::Equal => (), } @@ -380,11 +381,7 @@ impl PyMemoryView { } }; ret = vm.bool_eq(&a_val, &b_val); - if let Ok(b) = ret { - !b - } else { - true - } + if let Ok(b) = ret { !b } else { true } }); ret } diff --git a/vm/src/builtins/module.rs b/vm/src/builtins/module.rs index de55b9deae..8c8f22cf58 100644 --- a/vm/src/builtins/module.rs +++ b/vm/src/builtins/module.rs @@ -1,11 +1,11 @@ use super::{PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef}; use crate::{ - builtins::{pystr::AsPyStr, PyStrInterned}, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, + builtins::{PyStrInterned, pystr::AsPyStr}, class::PyClassImpl, convert::ToPyObject, function::{FuncArgs, PyMethodDef}, types::{GetAttr, Initializer, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "module")] @@ -183,11 +183,12 @@ impl Initializer for PyModule { type Args = ModuleInitArgs; fn init(zelf: PyRef, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> { - debug_assert!(zelf - .class() - .slots - .flags - .has_feature(crate::types::PyTypeFlags::HAS_DICT)); + debug_assert!( + zelf.class() + .slots + .flags + .has_feature(crate::types::PyTypeFlags::HAS_DICT) + ); zelf.init_dict(vm.ctx.intern_str(args.name.as_str()), args.doc, vm); Ok(()) } diff --git a/vm/src/builtins/namespace.rs b/vm/src/builtins/namespace.rs index 441fd014f0..38146baa72 100644 --- a/vm/src/builtins/namespace.rs +++ b/vm/src/builtins/namespace.rs @@ -1,5 +1,6 @@ -use super::{tuple::IntoPyTuple, PyTupleRef, PyType}; +use super::{PyTupleRef, PyType, tuple::IntoPyTuple}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyDict, class::PyClassImpl, function::{FuncArgs, PyComparisonValue}, @@ -7,7 +8,6 @@ use crate::{ types::{ Comparable, Constructor, DefaultConstructor, Initializer, PyComparisonOp, Representable, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; /// A simple attribute-based namespace. diff --git a/vm/src/builtins/object.rs b/vm/src/builtins/object.rs index aeb9e93cc6..cce1422d56 100644 --- a/vm/src/builtins/object.rs +++ b/vm/src/builtins/object.rs @@ -2,11 +2,11 @@ use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef}; use crate::common::hash::PyHash; use crate::types::PyTypeFlags; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, convert::ToPyResult, function::{Either, FuncArgs, PyArithmeticValue, PyComparisonValue, PySetterValue}, types::{Constructor, PyComparisonOp}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use itertools::Itertools; diff --git a/vm/src/builtins/property.rs b/vm/src/builtins/property.rs index 61e1ff1692..5bfae5a081 100644 --- a/vm/src/builtins/property.rs +++ b/vm/src/builtins/property.rs @@ -5,10 +5,10 @@ use super::{PyStrRef, PyType, PyTypeRef}; use crate::common::lock::PyRwLock; use crate::function::{IntoFuncArgs, PosArgs}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, function::{FuncArgs, PySetterValue}, types::{Constructor, GetDescriptor, Initializer}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "property", traverse)] diff --git a/vm/src/builtins/range.rs b/vm/src/builtins/range.rs index 602ea2d37f..b542a5f191 100644 --- a/vm/src/builtins/range.rs +++ b/vm/src/builtins/range.rs @@ -1,8 +1,9 @@ use super::{ - builtins_iter, tuple::tuple_hash, PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef, + PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef, builtins_iter, tuple::tuple_hash, }; use crate::{ - atomic_func, + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, atomic_func, class::PyClassImpl, common::hash::PyHash, function::{ArgIndex, FuncArgs, OptionalArg, PyComparisonValue}, @@ -11,8 +12,6 @@ use crate::{ AsMapping, AsSequence, Comparable, Hashable, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use malachite_bigint::{BigInt, Sign}; diff --git a/vm/src/builtins/set.rs b/vm/src/builtins/set.rs index 1ab1fe21cf..62a66c89b4 100644 --- a/vm/src/builtins/set.rs +++ b/vm/src/builtins/set.rs @@ -2,10 +2,11 @@ * Builtin set type with a sequence of unique items. */ use super::{ - builtins_iter, IterStatus, PositionIterInternal, PyDict, PyDictRef, PyGenericAlias, PyTupleRef, - PyType, PyTypeRef, + IterStatus, PositionIterInternal, PyDict, PyDictRef, PyGenericAlias, PyTupleRef, PyType, + PyTypeRef, builtins_iter, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, atomic_func, class::PyClassImpl, common::{ascii, hash::PyHash, lock::PyMutex, rc::PyRc}, @@ -21,7 +22,6 @@ use crate::{ }, utils::collection_repr, vm::VirtualMachine, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use once_cell::sync::Lazy; use rustpython_common::{ diff --git a/vm/src/builtins/singletons.rs b/vm/src/builtins/singletons.rs index 65b171a262..da0c718c46 100644 --- a/vm/src/builtins/singletons.rs +++ b/vm/src/builtins/singletons.rs @@ -1,10 +1,10 @@ use super::{PyStrRef, PyType, PyTypeRef}; use crate::{ + Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, convert::ToPyObject, protocol::PyNumberMethods, types::{AsNumber, Constructor, Representable}, - Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "NoneType")] diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index 5da3649115..4194360f4a 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -2,13 +2,13 @@ // spell-checker:ignore sliceobject use super::{PyStrRef, PyTupleRef, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, common::hash::{PyHash, PyUHash}, convert::ToPyObject, function::{ArgIndex, FuncArgs, OptionalArg, PyComparisonValue}, sliceable::SaturatedSlice, types::{Comparable, Constructor, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use malachite_bigint::{BigInt, ToBigInt}; use num_traits::{One, Signed, Zero}; @@ -264,11 +264,7 @@ impl Comparable for PySlice { let eq = vm.identical_or_equal(zelf.start_ref(vm), other.start_ref(vm))? && vm.identical_or_equal(&zelf.stop, &other.stop)? && vm.identical_or_equal(zelf.step_ref(vm), other.step_ref(vm))?; - if op == PyComparisonOp::Ne { - !eq - } else { - eq - } + if op == PyComparisonOp::Ne { !eq } else { eq } } PyComparisonOp::Gt | PyComparisonOp::Ge => None .or_else(|| { diff --git a/vm/src/builtins/staticmethod.rs b/vm/src/builtins/staticmethod.rs index 59a5b18b5d..8e2333da7f 100644 --- a/vm/src/builtins/staticmethod.rs +++ b/vm/src/builtins/staticmethod.rs @@ -1,10 +1,10 @@ use super::{PyStr, PyType, PyTypeRef}; use crate::{ + Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, common::lock::PyMutex, function::FuncArgs, types::{Callable, Constructor, GetDescriptor, Initializer, Representable}, - Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "staticmethod", traverse)] diff --git a/vm/src/builtins/str.rs b/vm/src/builtins/str.rs index f37a004297..bf9a9f679c 100644 --- a/vm/src/builtins/str.rs +++ b/vm/src/builtins/str.rs @@ -1,10 +1,12 @@ use super::{ + PositionIterInternal, PyBytesRef, PyDict, PyTupleRef, PyType, PyTypeRef, int::{PyInt, PyIntRef}, iter::IterStatus::{self, Exhausted}, - PositionIterInternal, PyBytesRef, PyDict, PyTupleRef, PyType, PyTypeRef, }; use crate::{ - anystr::{self, adjust_indices, AnyStr, AnyStrContainer, AnyStrWrapper}, + AsObject, Context, Py, PyExact, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, + TryFromBorrowedObject, VirtualMachine, + anystr::{self, AnyStr, AnyStrContainer, AnyStrWrapper, adjust_indices}, atomic_func, class::PyClassImpl, common::str::{BorrowedStr, PyStrKind, PyStrKindData}, @@ -20,8 +22,6 @@ use crate::{ AsMapping, AsNumber, AsSequence, Comparable, Constructor, Hashable, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible, }, - AsObject, Context, Py, PyExact, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, - TryFromBorrowedObject, VirtualMachine, }; use ascii::{AsciiStr, AsciiString}; use bstr::ByteSlice; @@ -904,11 +904,7 @@ impl PyStr { '\n' => 1, '\r' => { let is_rn = enumerated.next_if(|(_, ch)| *ch == '\n').is_some(); - if is_rn { - 2 - } else { - 1 - } + if is_rn { 2 } else { 1 } } '\x0b' | '\x0c' | '\x1c' | '\x1d' | '\x1e' | '\u{0085}' | '\u{2028}' | '\u{2029}' => ch.len_utf8(), diff --git a/vm/src/builtins/super.rs b/vm/src/builtins/super.rs index a0192cea5c..5f363ebea5 100644 --- a/vm/src/builtins/super.rs +++ b/vm/src/builtins/super.rs @@ -5,11 +5,11 @@ See also [CPython source code.](https://github.com/python/cpython/blob/50b48572d use super::{PyStr, PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, class::PyClassImpl, common::lock::PyRwLock, function::{FuncArgs, IntoFuncArgs, OptionalArg}, types::{Callable, Constructor, GetAttr, GetDescriptor, Initializer, Representable}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass(module = false, name = "super", traverse)] diff --git a/vm/src/builtins/traceback.rs b/vm/src/builtins/traceback.rs index 6506e95363..b0abbd006a 100644 --- a/vm/src/builtins/traceback.rs +++ b/vm/src/builtins/traceback.rs @@ -2,7 +2,7 @@ use rustpython_common::lock::PyMutex; use super::PyType; use crate::{ - class::PyClassImpl, frame::FrameRef, source_code::LineNumber, Context, Py, PyPayload, PyRef, + Context, Py, PyPayload, PyRef, class::PyClassImpl, frame::FrameRef, source_code::LineNumber, }; #[pyclass(module = false, name = "traceback", traverse)] diff --git a/vm/src/builtins/tuple.rs b/vm/src/builtins/tuple.rs index 9d1cc2f5ce..66cb2799a7 100644 --- a/vm/src/builtins/tuple.rs +++ b/vm/src/builtins/tuple.rs @@ -2,6 +2,7 @@ use super::{PositionIterInternal, PyGenericAlias, PyStrRef, PyType, PyTypeRef}; use crate::common::{hash::PyHash, lock::PyMutex}; use crate::object::{Traverse, TraverseFn}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, atomic_func, class::PyClassImpl, convert::{ToPyObject, TransmuteFromObject}, @@ -17,7 +18,6 @@ use crate::{ }, utils::collection_repr, vm::VirtualMachine, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use once_cell::sync::Lazy; use std::{fmt, marker::PhantomData}; diff --git a/vm/src/builtins/type.rs b/vm/src/builtins/type.rs index c3fc28cd60..08a15575ed 100644 --- a/vm/src/builtins/type.rs +++ b/vm/src/builtins/type.rs @@ -1,16 +1,18 @@ use super::{ - mappingproxy::PyMappingProxy, object, union_, PyClassMethod, PyDictRef, PyList, PyStr, - PyStrInterned, PyStrRef, PyTuple, PyTupleRef, PyWeak, + PyClassMethod, PyDictRef, PyList, PyStr, PyStrInterned, PyStrRef, PyTuple, PyTupleRef, PyWeak, + mappingproxy::PyMappingProxy, object, union_, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, builtins::{ + PyBaseExceptionRef, descriptor::{ MemberGetter, MemberKind, MemberSetter, PyDescriptorOwned, PyMemberDef, PyMemberDescriptor, }, function::PyCellRef, tuple::{IntoPyTuple, PyTupleTyped}, - PyBaseExceptionRef, }, class::{PyClassImpl, StaticType}, common::{ @@ -26,10 +28,8 @@ use crate::{ types::{ AsNumber, Callable, Constructor, GetAttr, PyTypeFlags, PyTypeSlots, Representable, SetAttr, }, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - VirtualMachine, }; -use indexmap::{map::Entry, IndexMap}; +use indexmap::{IndexMap, map::Entry}; use itertools::Itertools; use std::{borrow::Borrow, collections::HashSet, fmt, ops::Deref, pin::Pin, ptr::NonNull}; diff --git a/vm/src/builtins/union.rs b/vm/src/builtins/union.rs index 668d87bdce..f9dc8f3131 100644 --- a/vm/src/builtins/union.rs +++ b/vm/src/builtins/union.rs @@ -1,5 +1,6 @@ use super::{genericalias, type_}; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, builtins::{PyFrozenSet, PyStr, PyTuple, PyTupleRef, PyType}, class::PyClassImpl, @@ -8,7 +9,6 @@ use crate::{ function::PyComparisonValue, protocol::{PyMappingMethods, PyNumberMethods}, types::{AsMapping, AsNumber, Comparable, GetAttr, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use once_cell::sync::Lazy; use std::fmt; diff --git a/vm/src/builtins/weakproxy.rs b/vm/src/builtins/weakproxy.rs index f271e4cddb..d17bc75118 100644 --- a/vm/src/builtins/weakproxy.rs +++ b/vm/src/builtins/weakproxy.rs @@ -1,6 +1,6 @@ use super::{PyStr, PyStrRef, PyType, PyTypeRef, PyWeak}; use crate::{ - atomic_func, + Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, class::PyClassImpl, common::hash::PyHash, function::{OptionalArg, PyComparisonValue, PySetterValue}, @@ -10,7 +10,6 @@ use crate::{ AsMapping, AsSequence, Comparable, Constructor, GetAttr, Hashable, IterNext, Iterable, PyComparisonOp, Representable, SetAttr, }, - Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use once_cell::sync::Lazy; diff --git a/vm/src/builtins/weakref.rs b/vm/src/builtins/weakref.rs index 1d52225a26..9b2f248aa9 100644 --- a/vm/src/builtins/weakref.rs +++ b/vm/src/builtins/weakref.rs @@ -4,10 +4,10 @@ use crate::common::{ hash::{self, PyHash}, }; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, class::PyClassImpl, function::OptionalArg, types::{Callable, Comparable, Constructor, Hashable, PyComparisonOp, Representable}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; pub use crate::object::PyWeak; diff --git a/vm/src/builtins/zip.rs b/vm/src/builtins/zip.rs index 56c88f14c6..abd82b3ccb 100644 --- a/vm/src/builtins/zip.rs +++ b/vm/src/builtins/zip.rs @@ -1,11 +1,11 @@ use super::{PyType, PyTypeRef}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::PyTupleRef, class::PyClassImpl, function::{ArgIntoBool, OptionalArg, PosArgs}, protocol::{PyIter, PyIterReturn}, types::{Constructor, IterNext, Iterable, SelfIter}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use rustpython_common::atomic::{self, PyAtomic, Radium}; diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 79d4d96262..3754b75ee1 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -1,8 +1,9 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, anystr::{self, AnyStr, AnyStrContainer, AnyStrWrapper}, builtins::{ - pystr, PyBaseExceptionRef, PyByteArray, PyBytes, PyBytesRef, PyInt, PyIntRef, PyStr, - PyStrRef, PyTypeRef, + PyBaseExceptionRef, PyByteArray, PyBytes, PyBytesRef, PyInt, PyIntRef, PyStr, PyStrRef, + PyTypeRef, pystr, }, byte::bytes_from_object, cformat::cformat_bytes, @@ -13,7 +14,6 @@ use crate::{ protocol::PyBuffer, sequence::{SequenceExt, SequenceMutExt}, types::PyComparisonOp, - AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, }; use bstr::ByteSlice; use itertools::Itertools; diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index 79f4d68833..6e14034d0b 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -2,13 +2,13 @@ //! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting). use crate::{ + AsObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, builtins::{ - try_f64_to_bigint, tuple, PyBaseExceptionRef, PyByteArray, PyBytes, PyFloat, PyInt, PyStr, + PyBaseExceptionRef, PyByteArray, PyBytes, PyFloat, PyInt, PyStr, try_f64_to_bigint, tuple, }, function::ArgIntoFloat, protocol::PyBuffer, stdlib::builtins, - AsObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine, }; use itertools::Itertools; use num_traits::cast::ToPrimitive; diff --git a/vm/src/class.rs b/vm/src/class.rs index 3b7f1bffcb..bc38d6bd61 100644 --- a/vm/src/class.rs +++ b/vm/src/class.rs @@ -5,7 +5,7 @@ use crate::{ function::PyMethodDef, identifier, object::Py, - types::{hash_not_implemented, PyTypeFlags, PyTypeSlots}, + types::{PyTypeFlags, PyTypeSlots, hash_not_implemented}, vm::Context, }; use rustpython_common::static_cell; diff --git a/vm/src/codecs.rs b/vm/src/codecs.rs index 767bd873b6..e104097413 100644 --- a/vm/src/codecs.rs +++ b/vm/src/codecs.rs @@ -1,9 +1,9 @@ use crate::{ + AsObject, Context, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytesRef, PyStr, PyStrRef, PyTuple, PyTupleRef}, common::{ascii, lock::PyRwLock}, convert::ToPyObject, function::PyMethodDef, - AsObject, Context, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::{borrow::Cow, collections::HashMap, fmt::Write, ops::Range}; diff --git a/vm/src/convert/to_pyobject.rs b/vm/src/convert/to_pyobject.rs index c61296fe69..840c0c65fb 100644 --- a/vm/src/convert/to_pyobject.rs +++ b/vm/src/convert/to_pyobject.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyBaseExceptionRef, PyObjectRef, PyResult, VirtualMachine}; +use crate::{PyObjectRef, PyResult, VirtualMachine, builtins::PyBaseExceptionRef}; /// Implemented by any type that can be returned from a built-in Python function. /// diff --git a/vm/src/convert/try_from.rs b/vm/src/convert/try_from.rs index 8abe829803..941e1fef2a 100644 --- a/vm/src/convert/try_from.rs +++ b/vm/src/convert/try_from.rs @@ -1,7 +1,7 @@ use crate::{ + Py, VirtualMachine, builtins::PyFloat, object::{AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult}, - Py, VirtualMachine, }; use num_traits::ToPrimitive; diff --git a/vm/src/coroutine.rs b/vm/src/coroutine.rs index 5dd34a799d..56eb520b2c 100644 --- a/vm/src/coroutine.rs +++ b/vm/src/coroutine.rs @@ -1,9 +1,9 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyStrRef}, common::lock::PyMutex, frame::{ExecutionResult, FrameRef}, protocol::PyIterReturn, - AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 4baeef0bfc..7c8fd23834 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -4,9 +4,9 @@ //! And: http://code.activestate.com/recipes/578375/ use crate::{ + AsObject, Py, PyExact, PyObject, PyObjectRef, PyRefExact, PyResult, VirtualMachine, builtins::{PyInt, PyStr, PyStrInterned, PyStrRef}, convert::ToPyObject, - AsObject, Py, PyExact, PyObject, PyObjectRef, PyRefExact, PyResult, VirtualMachine, }; use crate::{ common::{ @@ -915,7 +915,7 @@ fn str_exact<'a>(obj: &'a PyObject, vm: &VirtualMachine) -> Option<&'a PyStr> { #[cfg(test)] mod tests { use super::*; - use crate::{common::ascii, Interpreter}; + use crate::{Interpreter, common::ascii}; #[test] fn test_insert() { diff --git a/vm/src/eval.rs b/vm/src/eval.rs index 35f27dc9d6..4c48efc700 100644 --- a/vm/src/eval.rs +++ b/vm/src/eval.rs @@ -1,4 +1,4 @@ -use crate::{compiler, scope::Scope, PyResult, VirtualMachine}; +use crate::{PyResult, VirtualMachine, compiler, scope::Scope}; pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult { match vm.compile(source, compiler::Mode::Eval, source_path.to_owned()) { diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 94a16f912e..5882fbe2bc 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -2,8 +2,9 @@ use self::types::{PyBaseException, PyBaseExceptionRef}; use crate::common::lock::PyRwLock; use crate::object::{Traverse, TraverseFn}; use crate::{ + AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{ - traceback::PyTracebackRef, PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, + PyNone, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, traceback::PyTracebackRef, }, class::{PyClassImpl, StaticType}, convert::{ToPyException, ToPyObject}, @@ -12,7 +13,6 @@ use crate::{ stdlib::sys, suggestion::offer_suggestions, types::{Callable, Constructor, Initializer, Representable}, - AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; @@ -1177,13 +1177,13 @@ pub(super) mod types { use crate::common::lock::PyRwLock; #[cfg_attr(target_arch = "wasm32", allow(unused_imports))] use crate::{ + AsObject, PyObjectRef, PyRef, PyResult, VirtualMachine, builtins::{ - traceback::PyTracebackRef, tuple::IntoPyTuple, PyInt, PyStrRef, PyTupleRef, PyTypeRef, + PyInt, PyStrRef, PyTupleRef, PyTypeRef, traceback::PyTracebackRef, tuple::IntoPyTuple, }, convert::ToPyResult, function::FuncArgs, types::{Constructor, Initializer}, - AsObject, PyObjectRef, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; diff --git a/vm/src/format.rs b/vm/src/format.rs index 8109ea00f4..7e9bb54265 100644 --- a/vm/src/format.rs +++ b/vm/src/format.rs @@ -1,9 +1,9 @@ use crate::{ + PyObject, PyResult, VirtualMachine, builtins::PyBaseExceptionRef, convert::{IntoPyException, ToPyException}, function::FuncArgs, stdlib::builtins, - PyObject, PyResult, VirtualMachine, }; use rustpython_format::*; diff --git a/vm/src/frame.rs b/vm/src/frame.rs index afa5c708e7..7cbe25909b 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -1,11 +1,12 @@ use crate::common::{boxvec::BoxVec, lock::PyMutex}; use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{ + PyBaseExceptionRef, PyCode, PyCoroutine, PyDict, PyDictRef, PyGenerator, PyList, PySet, + PySlice, PyStr, PyStrInterned, PyStrRef, PyTraceback, PyType, asyncgenerator::PyAsyncGenWrappedValue, function::{PyCell, PyCellRef, PyFunction}, tuple::{PyTuple, PyTupleRef, PyTupleTyped}, - PyBaseExceptionRef, PyCode, PyCoroutine, PyDict, PyDictRef, PyGenerator, PyList, PySet, - PySlice, PyStr, PyStrInterned, PyStrRef, PyTraceback, PyType, }, bytecode, convert::{IntoObject, ToPyResult}, @@ -17,7 +18,6 @@ use crate::{ source_code::SourceLocation, stdlib::{builtins, typing::_typing}, vm::{Context, PyMethod}, - AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use indexmap::IndexMap; use itertools::Itertools; @@ -277,15 +277,17 @@ impl Py { } pub fn next_external_frame(&self, vm: &VirtualMachine) -> Option { - self.f_back(vm).map(|mut back| loop { - back = if let Some(back) = back.to_owned().f_back(vm) { - back - } else { - break back; - }; + self.f_back(vm).map(|mut back| { + loop { + back = if let Some(back) = back.to_owned().f_back(vm) { + back + } else { + break back; + }; - if !back.is_internal_frame() { - break back; + if !back.is_internal_frame() { + break back; + } } }) } @@ -638,7 +640,7 @@ impl ExecutingFrame<'_> { match res { Ok(()) => {} Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => { - return Err(name_error(name, vm)) + return Err(name_error(name, vm)); } Err(e) => return Err(e), } @@ -649,7 +651,7 @@ impl ExecutingFrame<'_> { match self.globals.del_item(name, vm) { Ok(()) => {} Err(e) if e.fast_isinstance(vm.ctx.exceptions.key_error) => { - return Err(name_error(name, vm)) + return Err(name_error(name, vm)); } Err(e) => return Err(e), } diff --git a/vm/src/function/argument.rs b/vm/src/function/argument.rs index b0e731ff57..b7fd509ef1 100644 --- a/vm/src/function/argument.rs +++ b/vm/src/function/argument.rs @@ -1,8 +1,8 @@ use crate::{ + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyTupleRef, PyTypeRef}, convert::ToPyObject, object::{Traverse, TraverseFn}, - AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use indexmap::IndexMap; use itertools::Itertools; diff --git a/vm/src/function/arithmetic.rs b/vm/src/function/arithmetic.rs index b40e31e1b6..9f40ca7fec 100644 --- a/vm/src/function/arithmetic.rs +++ b/vm/src/function/arithmetic.rs @@ -1,7 +1,7 @@ use crate::{ + VirtualMachine, convert::{ToPyObject, TryFromObject}, object::{AsObject, PyObjectRef, PyResult}, - VirtualMachine, }; #[derive(result_like::OptionLike)] diff --git a/vm/src/function/buffer.rs b/vm/src/function/buffer.rs index f5d0dd03d6..91379e7a7f 100644 --- a/vm/src/function/buffer.rs +++ b/vm/src/function/buffer.rs @@ -1,9 +1,9 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, + VirtualMachine, builtins::{PyStr, PyStrRef}, common::borrow::{BorrowedValue, BorrowedValueMut}, protocol::PyBuffer, - AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, - VirtualMachine, }; // Python/getargs.c diff --git a/vm/src/function/builtin.rs b/vm/src/function/builtin.rs index bf9a5ed345..b8a408453d 100644 --- a/vm/src/function/builtin.rs +++ b/vm/src/function/builtin.rs @@ -1,7 +1,7 @@ use super::{FromArgs, FuncArgs}; use crate::{ - convert::ToPyResult, object::PyThreadingConstraint, Py, PyPayload, PyRef, PyResult, - VirtualMachine, + Py, PyPayload, PyRef, PyResult, VirtualMachine, convert::ToPyResult, + object::PyThreadingConstraint, }; use std::marker::PhantomData; diff --git a/vm/src/function/either.rs b/vm/src/function/either.rs index ceb79d55c9..08b96c7fe3 100644 --- a/vm/src/function/either.rs +++ b/vm/src/function/either.rs @@ -1,5 +1,5 @@ use crate::{ - convert::ToPyObject, AsObject, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, + AsObject, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, convert::ToPyObject, }; use std::borrow::Borrow; diff --git a/vm/src/function/fspath.rs b/vm/src/function/fspath.rs index 41e99b0542..69f11eb65d 100644 --- a/vm/src/function/fspath.rs +++ b/vm/src/function/fspath.rs @@ -1,9 +1,9 @@ use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBytes, PyBytesRef, PyStrRef}, convert::{IntoPyException, ToPyObject}, function::PyStr, protocol::PyBuffer, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use std::{ffi::OsStr, path::PathBuf}; diff --git a/vm/src/function/getset.rs b/vm/src/function/getset.rs index 827158e834..66e668ace6 100644 --- a/vm/src/function/getset.rs +++ b/vm/src/function/getset.rs @@ -2,10 +2,10 @@ */ use crate::{ + Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, convert::ToPyResult, function::{BorrowedParam, OwnedParam, RefParam}, object::PyThreadingConstraint, - Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; #[derive(result_like::OptionLike, is_macro::Is, Debug)] diff --git a/vm/src/function/method.rs b/vm/src/function/method.rs index adf53d7d93..d3d0b85fae 100644 --- a/vm/src/function/method.rs +++ b/vm/src/function/method.rs @@ -1,11 +1,11 @@ use crate::{ + Context, Py, PyObjectRef, PyPayload, PyRef, VirtualMachine, builtins::{ + PyType, builtin_func::{PyNativeFunction, PyNativeMethod}, descriptor::PyMethodDescriptor, - PyType, }, function::{IntoPyNativeFn, PyNativeFn}, - Context, Py, PyObjectRef, PyPayload, PyRef, VirtualMachine, }; bitflags::bitflags! { diff --git a/vm/src/function/mod.rs b/vm/src/function/mod.rs index 3bd6d0f74c..8e517f6ed5 100644 --- a/vm/src/function/mod.rs +++ b/vm/src/function/mod.rs @@ -15,7 +15,7 @@ pub use argument::{ }; pub use arithmetic::{PyArithmeticValue, PyComparisonValue}; pub use buffer::{ArgAsciiBuffer, ArgBytesLike, ArgMemoryBuffer, ArgStrOrBytesLike}; -pub use builtin::{static_func, static_raw_func, IntoPyNativeFn, PyNativeFn}; +pub use builtin::{IntoPyNativeFn, PyNativeFn, static_func, static_raw_func}; pub use either::Either; pub use fspath::FsPath; pub use getset::PySetterValue; @@ -24,7 +24,7 @@ pub use method::{HeapMethodDef, PyMethodDef, PyMethodFlags}; pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat, ArgPrimitiveIndex, ArgSize}; pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence}; -use crate::{builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyResult, VirtualMachine}; +use crate::{PyObject, PyResult, VirtualMachine, builtins::PyStr, convert::TryFromBorrowedObject}; use builtin::{BorrowedParam, OwnedParam, RefParam}; #[derive(Clone, Copy, PartialEq, Eq)] diff --git a/vm/src/function/number.rs b/vm/src/function/number.rs index 5f23543395..0e36f57ad1 100644 --- a/vm/src/function/number.rs +++ b/vm/src/function/number.rs @@ -1,5 +1,5 @@ use super::argument::OptionalArg; -use crate::{builtins::PyIntRef, AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine}; +use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::PyIntRef}; use malachite_bigint::BigInt; use num_complex::Complex64; use num_traits::PrimInt; diff --git a/vm/src/function/protocol.rs b/vm/src/function/protocol.rs index 295332e480..4b7e4c4cef 100644 --- a/vm/src/function/protocol.rs +++ b/vm/src/function/protocol.rs @@ -1,12 +1,12 @@ use super::IntoFuncArgs; use crate::{ - builtins::{iter::PySequenceIterator, PyDict, PyDictRef}, + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, + builtins::{PyDict, PyDictRef, iter::PySequenceIterator}, convert::ToPyObject, identifier, object::{Traverse, TraverseFn}, protocol::{PyIter, PyIterIter, PyMapping, PyMappingMethods}, types::{AsMapping, GenericMethod}, - AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::{borrow::Borrow, marker::PhantomData, ops::Deref}; diff --git a/vm/src/import.rs b/vm/src/import.rs index fbd563dabb..860f0b8a16 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -2,11 +2,11 @@ * Import mechanics */ use crate::{ - builtins::{list, traceback::PyTraceback, PyBaseExceptionRef, PyCode}, + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + builtins::{PyBaseExceptionRef, PyCode, list, traceback::PyTraceback}, scope::Scope, version::get_git_revision, - vm::{thread, VirtualMachine}, - AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + vm::{VirtualMachine, thread}, }; pub(crate) fn init_importlib_base(vm: &mut VirtualMachine) -> PyResult { diff --git a/vm/src/intern.rs b/vm/src/intern.rs index 5bb657f222..10aaa53454 100644 --- a/vm/src/intern.rs +++ b/vm/src/intern.rs @@ -1,8 +1,8 @@ use crate::{ + AsObject, Py, PyExact, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, VirtualMachine, builtins::{PyStr, PyStrInterned, PyTypeRef}, common::lock::PyRwLock, convert::ToPyObject, - AsObject, Py, PyExact, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, VirtualMachine, }; use std::{ borrow::{Borrow, ToOwned}, diff --git a/vm/src/iter.rs b/vm/src/iter.rs index 497dc20adc..1e13243792 100644 --- a/vm/src/iter.rs +++ b/vm/src/iter.rs @@ -1,4 +1,4 @@ -use crate::{types::PyComparisonOp, vm::VirtualMachine, PyObjectRef, PyResult}; +use crate::{PyObjectRef, PyResult, types::PyComparisonOp, vm::VirtualMachine}; use itertools::Itertools; pub trait PyExactSizeIterator<'a>: ExactSizeIterator + Sized { diff --git a/vm/src/object/core.rs b/vm/src/object/core.rs index 61c31a02e3..481111532a 100644 --- a/vm/src/object/core.rs +++ b/vm/src/object/core.rs @@ -11,9 +11,9 @@ //! PyRef may looking like to be called as PyObjectWeak by the rule, //! but not to do to remember it is a PyRef object. use super::{ + PyAtomicRef, ext::{AsObject, PyRefExact, PyResult}, payload::PyObjectPayload, - PyAtomicRef, }; use crate::object::traverse::{Traverse, TraverseFn}; use crate::object::traverse_object::PyObjVTable; diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index 129a6a79bb..8c6d367583 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -7,17 +7,17 @@ use crate::common::{ lock::PyRwLockReadGuard, }; use crate::{ + VirtualMachine, builtins::{PyBaseExceptionRef, PyStrInterned, PyType}, convert::{IntoPyException, ToPyObject, ToPyResult, TryFromObject}, vm::Context, - VirtualMachine, }; use std::{ borrow::Borrow, fmt, marker::PhantomData, ops::Deref, - ptr::{null_mut, NonNull}, + ptr::{NonNull, null_mut}, }; /* Python objects and references. diff --git a/vm/src/object/payload.rs b/vm/src/object/payload.rs index d5f3d6330b..6413d6ae06 100644 --- a/vm/src/object/payload.rs +++ b/vm/src/object/payload.rs @@ -1,9 +1,9 @@ use crate::object::{MaybeTraverse, Py, PyObjectRef, PyRef, PyResult}; use crate::{ + PyRefExact, builtins::{PyBaseExceptionRef, PyType, PyTypeRef}, types::PyTypeFlags, vm::{Context, VirtualMachine}, - PyRefExact, }; cfg_if::cfg_if! { diff --git a/vm/src/object/traverse.rs b/vm/src/object/traverse.rs index 43a039d331..5f93dc5c8b 100644 --- a/vm/src/object/traverse.rs +++ b/vm/src/object/traverse.rs @@ -2,7 +2,7 @@ use std::ptr::NonNull; use rustpython_common::lock::{PyMutex, PyRwLock}; -use crate::{function::Either, object::PyObjectPayload, AsObject, PyObject, PyObjectRef, PyRef}; +use crate::{AsObject, PyObject, PyObjectRef, PyRef, function::Either, object::PyObjectPayload}; pub type TraverseFn<'a> = dyn FnMut(&PyObject) + 'a; diff --git a/vm/src/object/traverse_object.rs b/vm/src/object/traverse_object.rs index b690b80f75..682ddf4876 100644 --- a/vm/src/object/traverse_object.rs +++ b/vm/src/object/traverse_object.rs @@ -1,10 +1,10 @@ use std::fmt; use crate::{ + PyObject, object::{ - debug_obj, drop_dealloc_obj, try_trace_obj, Erased, InstanceDict, PyInner, PyObjectPayload, + Erased, InstanceDict, PyInner, PyObjectPayload, debug_obj, drop_dealloc_obj, try_trace_obj, }, - PyObject, }; use super::{Traverse, TraverseFn}; diff --git a/vm/src/ospath.rs b/vm/src/ospath.rs index fe26f227d1..9dda60d621 100644 --- a/vm/src/ospath.rs +++ b/vm/src/ospath.rs @@ -1,9 +1,9 @@ use crate::{ + PyObjectRef, PyResult, VirtualMachine, builtins::PyBaseExceptionRef, convert::{ToPyException, TryFromObject}, function::FsPath, object::AsObject, - PyObjectRef, PyResult, VirtualMachine, }; use std::path::{Path, PathBuf}; diff --git a/vm/src/protocol/buffer.rs b/vm/src/protocol/buffer.rs index 0dfe3f0027..8692e4f78e 100644 --- a/vm/src/protocol/buffer.rs +++ b/vm/src/protocol/buffer.rs @@ -2,6 +2,7 @@ //! https://docs.python.org/3/c-api/buffer.html use crate::{ + Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, common::{ borrow::{BorrowedValue, BorrowedValueMut}, lock::{MapImmutable, PyMutex, PyMutexGuard}, @@ -9,7 +10,6 @@ use crate::{ object::PyObjectPayload, sliceable::SequenceIndexOp, types::Unconstructible, - Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use itertools::Itertools; use std::{borrow::Cow, fmt::Debug, ops::Range}; diff --git a/vm/src/protocol/iter.rs b/vm/src/protocol/iter.rs index d9c49ed15f..345914e411 100644 --- a/vm/src/protocol/iter.rs +++ b/vm/src/protocol/iter.rs @@ -1,8 +1,8 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, builtins::iter::PySequenceIterator, convert::{ToPyObject, ToPyResult}, object::{Traverse, TraverseFn}, - AsObject, PyObject, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine, }; use std::borrow::Borrow; use std::ops::Deref; diff --git a/vm/src/protocol/mapping.rs b/vm/src/protocol/mapping.rs index 986b806f6c..cbecc8762e 100644 --- a/vm/src/protocol/mapping.rs +++ b/vm/src/protocol/mapping.rs @@ -1,12 +1,12 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine, builtins::{ + PyDict, PyStrInterned, dict::{PyDictItems, PyDictKeys, PyDictValues}, type_::PointerSlot, - PyDict, PyStrInterned, }, convert::ToPyResult, object::{Traverse, TraverseFn}, - AsObject, PyObject, PyObjectRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; diff --git a/vm/src/protocol/number.rs b/vm/src/protocol/number.rs index 01829bb553..65c4eaad79 100644 --- a/vm/src/protocol/number.rs +++ b/vm/src/protocol/number.rs @@ -3,13 +3,13 @@ use std::ops::Deref; use crossbeam_utils::atomic::AtomicCell; use crate::{ - builtins::{int, PyByteArray, PyBytes, PyComplex, PyFloat, PyInt, PyIntRef, PyStr}, + AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, + VirtualMachine, + builtins::{PyByteArray, PyBytes, PyComplex, PyFloat, PyInt, PyIntRef, PyStr, int}, common::int::bytes_to_int, function::ArgBytesLike, object::{Traverse, TraverseFn}, stdlib::warnings, - AsObject, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, - VirtualMachine, }; pub type PyNumberUnaryFunc = fn(PyNumber, &VirtualMachine) -> PyResult; diff --git a/vm/src/protocol/object.rs b/vm/src/protocol/object.rs index 8b9c0e446c..4e69cf38a2 100644 --- a/vm/src/protocol/object.rs +++ b/vm/src/protocol/object.rs @@ -2,9 +2,10 @@ //! https://docs.python.org/3/c-api/object.html use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{ - pystr::AsPyStr, PyAsyncGen, PyBytes, PyDict, PyDictRef, PyGenericAlias, PyInt, PyList, - PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, + PyAsyncGen, PyBytes, PyDict, PyDictRef, PyGenericAlias, PyInt, PyList, PyStr, PyStrRef, + PyTuple, PyTupleRef, PyType, PyTypeRef, pystr::AsPyStr, }, bytesinner::ByteInnerNewOptions, common::{hash::PyHash, str::to_ascii}, @@ -14,7 +15,6 @@ use crate::{ object::PyPayload, protocol::{PyIter, PyMapping, PySequence}, types::{Constructor, PyComparisonOp}, - AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; // RustPython doesn't need these items diff --git a/vm/src/protocol/sequence.rs b/vm/src/protocol/sequence.rs index 62cf828e40..46ac0c8be7 100644 --- a/vm/src/protocol/sequence.rs +++ b/vm/src/protocol/sequence.rs @@ -1,10 +1,10 @@ use crate::{ - builtins::{type_::PointerSlot, PyList, PyListRef, PySlice, PyTuple, PyTupleRef}, + PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, + builtins::{PyList, PyListRef, PySlice, PyTuple, PyTupleRef, type_::PointerSlot}, convert::ToPyObject, function::PyArithmeticValue, object::{Traverse, TraverseFn}, protocol::{PyMapping, PyNumberBinaryOp}, - PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; diff --git a/vm/src/py_io.rs b/vm/src/py_io.rs index 8091b75afc..0d7c319bc0 100644 --- a/vm/src/py_io.rs +++ b/vm/src/py_io.rs @@ -1,7 +1,7 @@ use crate::{ + PyObject, PyObjectRef, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytes, PyStr}, common::ascii, - PyObject, PyObjectRef, PyResult, VirtualMachine, }; use std::{fmt, io, ops}; diff --git a/vm/src/py_serde.rs b/vm/src/py_serde.rs index b4b12e430d..ea72879e42 100644 --- a/vm/src/py_serde.rs +++ b/vm/src/py_serde.rs @@ -3,7 +3,7 @@ use num_traits::sign::Signed; use serde::de::{DeserializeSeed, Visitor}; use serde::ser::{Serialize, SerializeMap, SerializeSeq}; -use crate::builtins::{bool_, dict::PyDictRef, float, int, list::PyList, tuple::PyTuple, PyStr}; +use crate::builtins::{PyStr, bool_, dict::PyDictRef, float, int, list::PyList, tuple::PyTuple}; use crate::{AsObject, PyObject, PyObjectRef, VirtualMachine}; #[inline] diff --git a/vm/src/scope.rs b/vm/src/scope.rs index 47a1e5e3ff..12b878f847 100644 --- a/vm/src/scope.rs +++ b/vm/src/scope.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyDictRef, function::ArgMapping, VirtualMachine}; +use crate::{VirtualMachine, builtins::PyDictRef, function::ArgMapping}; use std::fmt; #[derive(Clone)] diff --git a/vm/src/sequence.rs b/vm/src/sequence.rs index 3f2d1e94d2..fc6e216809 100644 --- a/vm/src/sequence.rs +++ b/vm/src/sequence.rs @@ -1,10 +1,10 @@ use crate::{ + AsObject, PyObject, PyObjectRef, PyResult, builtins::PyIntRef, function::OptionalArg, sliceable::SequenceIndexOp, types::PyComparisonOp, - vm::{VirtualMachine, MAX_MEMORY_SIZE}, - AsObject, PyObject, PyObjectRef, PyResult, + vm::{MAX_MEMORY_SIZE, VirtualMachine}, }; use optional::Optioned; use std::ops::{Deref, Range}; diff --git a/vm/src/signal.rs b/vm/src/signal.rs index 7489282de2..346664fa24 100644 --- a/vm/src/signal.rs +++ b/vm/src/signal.rs @@ -69,7 +69,7 @@ pub fn assert_in_range(signum: i32, vm: &VirtualMachine) -> PyResult<()> { #[allow(dead_code)] #[cfg(not(target_arch = "wasm32"))] pub fn set_interrupt_ex(signum: i32, vm: &VirtualMachine) -> PyResult<()> { - use crate::stdlib::signal::_signal::{run_signal, SIG_DFL, SIG_IGN}; + use crate::stdlib::signal::_signal::{SIG_DFL, SIG_IGN, run_signal}; assert_in_range(signum, vm)?; match signum as usize { diff --git a/vm/src/sliceable.rs b/vm/src/sliceable.rs index 257d325651..cbc25e4e18 100644 --- a/vm/src/sliceable.rs +++ b/vm/src/sliceable.rs @@ -1,7 +1,7 @@ // export through sliceable module, not slice. use crate::{ - builtins::{int::PyInt, slice::PySlice}, PyObject, PyResult, VirtualMachine, + builtins::{int::PyInt, slice::PySlice}, }; use malachite_bigint::BigInt; use num_traits::{Signed, ToPrimitive}; @@ -357,13 +357,8 @@ impl SaturatedSlice { if step == 0 { return Err(vm.new_value_error("slice step cannot be zero".to_owned())); } - let start = to_isize_index(vm, slice.start_ref(vm))?.unwrap_or_else(|| { - if step.is_negative() { - isize::MAX - } else { - 0 - } - }); + let start = to_isize_index(vm, slice.start_ref(vm))? + .unwrap_or_else(|| if step.is_negative() { isize::MAX } else { 0 }); let stop = to_isize_index(vm, &slice.stop(vm))?.unwrap_or_else(|| { if step.is_negative() { diff --git a/vm/src/stdlib/ast.rs b/vm/src/stdlib/ast.rs index 616d84368c..7dd893646e 100644 --- a/vm/src/stdlib/ast.rs +++ b/vm/src/stdlib/ast.rs @@ -6,14 +6,14 @@ mod r#gen; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, + VirtualMachine, builtins::{self, PyDict, PyModule, PyStrRef, PyType}, class::{PyClassImpl, StaticType}, - compiler::core::bytecode::OpArgType, compiler::CompileError, + compiler::core::bytecode::OpArgType, convert::ToPyException, source_code::{LinearLocator, OneIndexed, SourceLocation, SourceRange}, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, - VirtualMachine, }; use num_complex::Complex64; use num_traits::{ToPrimitive, Zero}; @@ -26,9 +26,9 @@ use rustpython_parser as parser; #[pymodule] mod _ast { use crate::{ + AsObject, Context, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyStrRef, PyTupleRef}, function::FuncArgs, - AsObject, Context, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; #[pyattr] #[pyclass(module = "_ast", name = "AST")] diff --git a/vm/src/stdlib/atexit.rs b/vm/src/stdlib/atexit.rs index dbeda76741..b1832b5481 100644 --- a/vm/src/stdlib/atexit.rs +++ b/vm/src/stdlib/atexit.rs @@ -3,7 +3,7 @@ pub(crate) use atexit::make_module; #[pymodule] mod atexit { - use crate::{function::FuncArgs, AsObject, PyObjectRef, PyResult, VirtualMachine}; + use crate::{AsObject, PyObjectRef, PyResult, VirtualMachine, function::FuncArgs}; #[pyfunction] fn register(func: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef { diff --git a/vm/src/stdlib/builtins.rs b/vm/src/stdlib/builtins.rs index cc9b0a8be7..22aa11dc43 100644 --- a/vm/src/stdlib/builtins.rs +++ b/vm/src/stdlib/builtins.rs @@ -1,7 +1,7 @@ //! Builtin function definitions. //! //! Implements the list of [builtin Python functions](https://docs.python.org/3/library/builtins.html). -use crate::{builtins::PyModule, class::PyClassImpl, Py, VirtualMachine}; +use crate::{Py, VirtualMachine, builtins::PyModule, class::PyClassImpl}; pub(crate) use builtins::{__module_def, DOC}; pub use builtins::{ascii, print, reversed}; @@ -10,13 +10,14 @@ mod builtins { use std::io::IsTerminal; use crate::{ + AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{ + PyByteArray, PyBytes, PyDictRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, enumerate::PyReverseSequenceIterator, function::{PyCellRef, PyFunction}, int::PyIntRef, iter::PyCallableIterator, list::{PyList, SortOptions}, - PyByteArray, PyBytes, PyDictRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, }, common::{hash::PyHash, str::to_ascii}, function::{ @@ -29,7 +30,6 @@ mod builtins { readline::{Readline, ReadlineResult}, stdlib::sys, types::PyComparisonOp, - AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use num_traits::{Signed, ToPrimitive}; @@ -157,8 +157,7 @@ mod builtins { #[cfg(not(feature = "rustpython-parser"))] { - const PARSER_NOT_SUPPORTED: &str = - "can't compile() source code when the `parser` feature of rustpython is disabled"; + const PARSER_NOT_SUPPORTED: &str = "can't compile() source code when the `parser` feature of rustpython is disabled"; Err(vm.new_type_error(PARSER_NOT_SUPPORTED.to_owned())) } #[cfg(feature = "rustpython-parser")] @@ -535,7 +534,7 @@ mod builtins { None => { return default.ok_or_else(|| { vm.new_value_error(format!("{func_name}() arg is an empty sequence")) - }) + }); } }; diff --git a/vm/src/stdlib/codecs.rs b/vm/src/stdlib/codecs.rs index 71317bf484..976545f64b 100644 --- a/vm/src/stdlib/codecs.rs +++ b/vm/src/stdlib/codecs.rs @@ -4,10 +4,10 @@ pub(crate) use _codecs::make_module; mod _codecs { use crate::common::encodings; use crate::{ + AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyBytes, PyBytesRef, PyStr, PyStrRef, PyTuple}, codecs, function::{ArgBytesLike, FuncArgs}, - AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use std::ops::Range; diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 5a9a172d53..fc867db2b1 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -3,6 +3,7 @@ pub(crate) use _collections::make_module; #[pymodule] mod _collections { use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func, builtins::{ IterStatus::{Active, Exhausted}, @@ -20,7 +21,6 @@ mod _collections { Iterable, PyComparisonOp, Representable, SelfIter, }, utils::collection_repr, - AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use std::cmp::max; diff --git a/vm/src/stdlib/ctypes/function.rs b/vm/src/stdlib/ctypes/function.rs index bf7f0b9adf..a7ee07744b 100644 --- a/vm/src/stdlib/ctypes/function.rs +++ b/vm/src/stdlib/ctypes/function.rs @@ -1,5 +1,5 @@ -use crate::stdlib::ctypes::PyCData; use crate::PyObjectRef; +use crate::stdlib::ctypes::PyCData; use crossbeam_utils::atomic::AtomicCell; use rustpython_common::lock::PyRwLock; use std::ffi::c_void; diff --git a/vm/src/stdlib/errno.rs b/vm/src/stdlib/errno.rs index a142d68a34..247e2a2340 100644 --- a/vm/src/stdlib/errno.rs +++ b/vm/src/stdlib/errno.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; #[pymodule] mod errno {} @@ -38,9 +38,9 @@ pub mod errors { WSAEPROVIDERFAILEDINIT, WSAEREFUSED, WSAEREMOTE, WSAESHUTDOWN, WSAESOCKTNOSUPPORT, WSAESTALE, WSAETIMEDOUT, WSAETOOMANYREFS, WSAEUSERS, WSAEWOULDBLOCK, WSAHOST_NOT_FOUND, WSAID_ACCEPTEX, WSAID_CONNECTEX, WSAID_DISCONNECTEX, WSAID_GETACCEPTEXSOCKADDRS, - WSAID_TRANSMITFILE, WSAID_TRANSMITPACKETS, WSAID_WSAPOLL, WSAID_WSARECVMSG, - WSANOTINITIALISED, WSANO_DATA, WSANO_RECOVERY, WSAPROTOCOL_LEN, WSASERVICE_NOT_FOUND, - WSASYSCALLFAILURE, WSASYSNOTREADY, WSASYS_STATUS_LEN, WSATRY_AGAIN, WSATYPE_NOT_FOUND, + WSAID_TRANSMITFILE, WSAID_TRANSMITPACKETS, WSAID_WSAPOLL, WSAID_WSARECVMSG, WSANO_DATA, + WSANO_RECOVERY, WSANOTINITIALISED, WSAPROTOCOL_LEN, WSASERVICE_NOT_FOUND, + WSASYS_STATUS_LEN, WSASYSCALLFAILURE, WSASYSNOTREADY, WSATRY_AGAIN, WSATYPE_NOT_FOUND, WSAVERNOTSUPPORTED, }, }; diff --git a/vm/src/stdlib/functools.rs b/vm/src/stdlib/functools.rs index d13b9b84f6..145d95d6ff 100644 --- a/vm/src/stdlib/functools.rs +++ b/vm/src/stdlib/functools.rs @@ -2,7 +2,7 @@ pub(crate) use _functools::make_module; #[pymodule] mod _functools { - use crate::{function::OptionalArg, protocol::PyIter, PyObjectRef, PyResult, VirtualMachine}; + use crate::{PyObjectRef, PyResult, VirtualMachine, function::OptionalArg, protocol::PyIter}; #[pyfunction] fn reduce( diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index d8727e74ff..5c3f4bf61d 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -1,11 +1,11 @@ use crate::frozen::FrozenModule; -use crate::{builtins::PyBaseExceptionRef, VirtualMachine}; +use crate::{VirtualMachine, builtins::PyBaseExceptionRef}; pub(crate) use _imp::make_module; #[cfg(feature = "threading")] #[pymodule(sub)] mod lock { - use crate::{stdlib::thread::RawRMutex, PyResult, VirtualMachine}; + use crate::{PyResult, VirtualMachine, stdlib::thread::RawRMutex}; static IMP_LOCK: RawRMutex = RawRMutex::INIT; @@ -60,7 +60,9 @@ impl FrozenError { use FrozenError::*; let msg = match self { BadName | NotFound => format!("No such frozen object named {mod_name}"), - Disabled => format!("Frozen modules are disabled and the frozen object named {mod_name} is not essential"), + Disabled => format!( + "Frozen modules are disabled and the frozen object named {mod_name} is not essential" + ), Excluded => format!("Excluded frozen object named {mod_name}"), Invalid => format!("Frozen object named {mod_name} is invalid"), }; @@ -80,9 +82,10 @@ fn find_frozen(name: &str, vm: &VirtualMachine) -> Result PyBaseExceptionRef { @@ -118,6 +118,8 @@ impl std::os::fd::AsRawFd for Fildes { mod _io { use super::*; use crate::{ + AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, + TryFromBorrowedObject, TryFromObject, builtins::{ PyBaseExceptionRef, PyByteArray, PyBytes, PyBytesRef, PyIntRef, PyMemoryView, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef, @@ -140,8 +142,6 @@ mod _io { Callable, Constructor, DefaultConstructor, Destructor, Initializer, IterNext, Iterable, }, vm::VirtualMachine, - AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromBorrowedObject, TryFromObject, }; use bstr::ByteSlice; use crossbeam_utils::atomic::AtomicCell; @@ -149,7 +149,7 @@ mod _io { use num_traits::ToPrimitive; use std::{ borrow::Cow, - io::{self, prelude::*, Cursor, SeekFrom}, + io::{self, Cursor, SeekFrom, prelude::*}, ops::Range, }; @@ -319,11 +319,7 @@ mod _io { // For Cursor, fill_buf returns all of the remaining data unlike other BufReads which have outer reading source. // Unless we add other data by write, there will be no more data. let buf = self.cursor.fill_buf().map_err(|err| os_err(vm, err))?; - if size < buf.len() { - &buf[..size] - } else { - buf - } + if size < buf.len() { &buf[..size] } else { buf } }; let buf = match available.find_byte(byte) { Some(i) => available[..=i].to_vec(), @@ -2496,7 +2492,7 @@ mod _io { _ => { return Err( vm.new_value_error(format!("invalid whence ({how}, should be 0, 1 or 2)")) - ) + ); } }; use crate::types::PyComparisonOp; @@ -3006,7 +3002,7 @@ mod _io { } fn parse_decoder_state(state: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyBytesRef, i32)> { - use crate::builtins::{int, PyTuple}; + use crate::builtins::{PyTuple, int}; let state_err = || vm.new_type_error("illegal decoder state".to_owned()); let state = state.downcast::().map_err(|_| state_err())?; match state.as_slice() { @@ -4032,8 +4028,9 @@ mod _io { #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] #[pymodule] mod fileio { - use super::{Offset, _io::*}; + use super::{_io::*, Offset}; use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyStr, PyStrRef}, common::crt_fd::Fd, convert::ToPyException, @@ -4041,7 +4038,6 @@ mod fileio { ospath::{IOErrorBuilder, OsPath, OsPathOrFd}, stdlib::os, types::{Constructor, DefaultConstructor, Initializer, Representable}, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use std::io::{Read, Write}; diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index eb800a0b1f..65c1482057 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -4,9 +4,11 @@ pub(crate) use decl::make_module; mod decl { use crate::stdlib::itertools::decl::int::get_value; use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, PyWeakRef, TryFromObject, + VirtualMachine, builtins::{ - int, tuple::IntoPyTuple, PyGenericAlias, PyInt, PyIntRef, PyList, PyTuple, PyTupleRef, - PyTypeRef, + PyGenericAlias, PyInt, PyIntRef, PyList, PyTuple, PyTupleRef, PyTypeRef, int, + tuple::IntoPyTuple, }, common::{ lock::{PyMutex, PyRwLock, PyRwLockWriteGuard}, @@ -18,8 +20,6 @@ mod decl { protocol::{PyIter, PyIterReturn, PyNumber}, stdlib::sys, types::{Constructor, IterNext, Iterable, Representable, SelfIter}, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, PyWeakRef, TryFromObject, - VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use malachite_bigint::BigInt; diff --git a/vm/src/stdlib/marshal.rs b/vm/src/stdlib/marshal.rs index 35f9b93d5f..fd7332e7c2 100644 --- a/vm/src/stdlib/marshal.rs +++ b/vm/src/stdlib/marshal.rs @@ -5,6 +5,7 @@ mod decl { use crate::builtins::code::{CodeObject, Literal, PyObjBag}; use crate::class::StaticType; use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{ PyBool, PyByteArray, PyBytes, PyCode, PyComplex, PyDict, PyEllipsis, PyFloat, PyFrozenSet, PyInt, PyList, PyNone, PySet, PyStopIteration, PyStr, PyTuple, @@ -13,7 +14,6 @@ mod decl { function::{ArgBytesLike, OptionalArg}, object::AsObject, protocol::PyBuffer, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use malachite_bigint::BigInt; use num_complex::Complex64; diff --git a/vm/src/stdlib/mod.rs b/vm/src/stdlib/mod.rs index ca8f8f0bfd..529a40e861 100644 --- a/vm/src/stdlib/mod.rs +++ b/vm/src/stdlib/mod.rs @@ -50,7 +50,7 @@ mod winapi; #[cfg(windows)] mod winreg; -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; use std::{borrow::Cow, collections::HashMap}; pub type StdlibInitFunc = Box PyRef)>; diff --git a/vm/src/stdlib/msvcrt.rs b/vm/src/stdlib/msvcrt.rs index 2572494671..7b3620ad51 100644 --- a/vm/src/stdlib/msvcrt.rs +++ b/vm/src/stdlib/msvcrt.rs @@ -3,10 +3,10 @@ pub use msvcrt::*; #[pymodule] mod msvcrt { use crate::{ + PyRef, PyResult, VirtualMachine, builtins::{PyBytes, PyStrRef}, common::suppress_iph, stdlib::os::errno_err, - PyRef, PyResult, VirtualMachine, }; use itertools::Itertools; use windows_sys::Win32::{ diff --git a/vm/src/stdlib/nt.rs b/vm/src/stdlib/nt.rs index 09d26ba279..34fa8792d5 100644 --- a/vm/src/stdlib/nt.rs +++ b/vm/src/stdlib/nt.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; pub use module::raw_set_handle_inheritable; @@ -11,13 +11,13 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule(name = "nt", with(super::os::_os))] pub(crate) mod module { use crate::{ + PyResult, TryFromObject, VirtualMachine, builtins::{PyDictRef, PyListRef, PyStrRef, PyTupleRef}, common::{crt_fd::Fd, os::last_os_error, suppress_iph}, convert::ToPyException, function::{Either, OptionalArg}, ospath::OsPath, - stdlib::os::{errno_err, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, _os}, - PyResult, TryFromObject, VirtualMachine, + stdlib::os::{_os, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, errno_err}, }; use libc::intptr_t; use std::{ diff --git a/vm/src/stdlib/operator.rs b/vm/src/stdlib/operator.rs index 19c1f4b61b..d1a4b376e8 100644 --- a/vm/src/stdlib/operator.rs +++ b/vm/src/stdlib/operator.rs @@ -4,6 +4,7 @@ pub(crate) use _operator::make_module; mod _operator { use crate::common::cmp; use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyInt, PyIntRef, PyStr, PyStrRef, PyTupleRef, PyTypeRef}, function::Either, function::{ArgBytesLike, FuncArgs, KwArgs, OptionalArg}, @@ -11,7 +12,6 @@ mod _operator { protocol::PyIter, recursion::ReprGuard, types::{Callable, Constructor, PyComparisonOp, Representable}, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyfunction] @@ -336,7 +336,7 @@ mod _operator { _ => { return Err(vm.new_type_error( "unsupported operand types(s) or combination of types".to_owned(), - )) + )); } }; Ok(res) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 6a4233f3be..39701cb3a3 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1,9 +1,9 @@ use crate::{ + AsObject, Py, PyPayload, PyResult, VirtualMachine, builtins::{PyBaseExceptionRef, PyModule, PySet}, common::crt_fd::Fd, convert::ToPyException, function::{ArgumentError, FromArgs, FuncArgs}, - AsObject, Py, PyPayload, PyResult, VirtualMachine, }; use std::{ffi, fs, io, path::Path}; @@ -125,8 +125,9 @@ fn bytes_as_osstr<'a>(b: &'a [u8], vm: &VirtualMachine) -> PyResult<&'a ffi::OsS #[pymodule(sub)] pub(super) mod _os { - use super::{errno_err, DirFd, FollowSymlinks, SupportFunc}; + use super::{DirFd, FollowSymlinks, SupportFunc, errno_err}; use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, builtins::{ PyBytesRef, PyGenericAlias, PyIntRef, PyStrRef, PyTuple, PyTupleRef, PyTypeRef, }, @@ -144,7 +145,6 @@ pub(super) mod _os { types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter}, utils::ToCString, vm::VirtualMachine, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, }; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; @@ -303,11 +303,7 @@ pub(super) mod _os { #[cfg(target_os = "redox")] let [] = dir_fd.0; let res = unsafe { libc::mkdir(path.as_ptr(), mode as _) }; - if res < 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if res < 0 { Err(errno_err(vm)) } else { Ok(()) } } #[pyfunction] @@ -1011,11 +1007,7 @@ pub(super) mod _os { std::mem::transmute::<[i32; 2], i64>(distance_to_move) } }; - if res < 0 { - Err(errno_err(vm)) - } else { - Ok(res) - } + if res < 0 { Err(errno_err(vm)) } else { Ok(res) } } #[pyfunction] @@ -1100,7 +1092,7 @@ pub(super) mod _os { (Some(_), Some(_)) => { return Err(vm.new_value_error( "utime: you may specify either 'times' or 'ns' but not both".to_owned(), - )) + )); } }; utime_impl(args.path, acc, modif, args.dir_fd, args.follow_symlinks, vm) @@ -1138,11 +1130,7 @@ pub(super) mod _os { }, ) }; - if ret < 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if ret < 0 { Err(errno_err(vm)) } else { Ok(()) } } #[cfg(target_os = "redox")] { diff --git a/vm/src/stdlib/posix.rs b/vm/src/stdlib/posix.rs index 77ebf9e620..05b1d8addd 100644 --- a/vm/src/stdlib/posix.rs +++ b/vm/src/stdlib/posix.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; use std::os::unix::io::RawFd; pub fn raw_set_inheritable(fd: RawFd, inheritable: bool) -> nix::Result<()> { @@ -21,16 +21,16 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule(name = "posix", with(super::os::_os))] pub mod module { use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, builtins::{PyDictRef, PyInt, PyListRef, PyStrRef, PyTupleRef, PyTypeRef}, convert::{IntoPyException, ToPyObject, TryFromObject}, function::{Either, KwArgs, OptionalArg}, ospath::{IOErrorBuilder, OsPath, OsPathOrFd}, stdlib::os::{ - errno_err, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, _os, fs_metadata, + _os, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, errno_err, fs_metadata, }, types::{Constructor, Representable}, utils::ToCString, - AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine, }; use bitflags::bitflags; use nix::{ @@ -352,11 +352,7 @@ pub mod module { { let [] = args.dir_fd.0; let res = unsafe { libc::symlink(src.as_ptr(), dst.as_ptr()) }; - if res < 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if res < 0 { Err(errno_err(vm)) } else { Ok(()) } } } @@ -604,21 +600,13 @@ pub mod module { ) }, }; - if ret != 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if ret != 0 { Err(errno_err(vm)) } else { Ok(()) } } #[cfg(target_vendor = "apple")] fn mknod(self, vm: &VirtualMachine) -> PyResult<()> { let [] = self.dir_fd.0; let ret = self._mknod(vm)?; - if ret != 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if ret != 0 { Err(errno_err(vm)) } else { Ok(()) } } } @@ -863,7 +851,7 @@ pub mod module { #[pyfunction] fn set_blocking(fd: RawFd, blocking: bool, vm: &VirtualMachine) -> PyResult<()> { let _set_flag = || { - use nix::fcntl::{fcntl, FcntlArg, OFlag}; + use nix::fcntl::{FcntlArg, OFlag, fcntl}; let flags = OFlag::from_bits_truncate(fcntl(fd, FcntlArg::F_GETFL)?); let mut new_flags = flags; @@ -1618,11 +1606,7 @@ pub mod module { #[pyfunction] fn _fcopyfile(in_fd: i32, out_fd: i32, flags: i32, vm: &VirtualMachine) -> PyResult<()> { let ret = unsafe { fcopyfile(in_fd, out_fd, std::ptr::null_mut(), flags as u32) }; - if ret < 0 { - Err(errno_err(vm)) - } else { - Ok(()) - } + if ret < 0 { Err(errno_err(vm)) } else { Ok(()) } } #[pyfunction] diff --git a/vm/src/stdlib/posix_compat.rs b/vm/src/stdlib/posix_compat.rs index 95ed932fe5..334aa597ce 100644 --- a/vm/src/stdlib/posix_compat.rs +++ b/vm/src/stdlib/posix_compat.rs @@ -1,5 +1,5 @@ //! `posix` compatible module for `not(any(unix, windows))` -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let module = module::make_module(vm); @@ -10,10 +10,10 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { #[pymodule(name = "posix", with(super::os::_os))] pub(crate) mod module { use crate::{ + PyObjectRef, PyResult, VirtualMachine, builtins::PyStrRef, ospath::OsPath, - stdlib::os::{DirFd, SupportFunc, TargetIsDirectory, _os}, - PyObjectRef, PyResult, VirtualMachine, + stdlib::os::{_os, DirFd, SupportFunc, TargetIsDirectory}, }; use std::env; diff --git a/vm/src/stdlib/pwd.rs b/vm/src/stdlib/pwd.rs index 0edca9c0a6..f6c277242c 100644 --- a/vm/src/stdlib/pwd.rs +++ b/vm/src/stdlib/pwd.rs @@ -3,11 +3,11 @@ pub(crate) use pwd::make_module; #[pymodule] mod pwd { use crate::{ + PyObjectRef, PyResult, VirtualMachine, builtins::{PyIntRef, PyStrRef}, convert::{IntoPyException, ToPyObject}, exceptions, types::PyStructSequence, - PyObjectRef, PyResult, VirtualMachine, }; use nix::unistd::{self, User}; use std::ptr::NonNull; diff --git a/vm/src/stdlib/signal.rs b/vm/src/stdlib/signal.rs index da7c934552..0c47ca082e 100644 --- a/vm/src/stdlib/signal.rs +++ b/vm/src/stdlib/signal.rs @@ -1,4 +1,4 @@ -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let module = _signal::make_module(vm); @@ -13,10 +13,10 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { pub(crate) mod _signal { #[cfg(any(unix, windows))] use crate::{ - convert::{IntoPyException, TryFromBorrowedObject}, Py, + convert::{IntoPyException, TryFromBorrowedObject}, }; - use crate::{signal, PyObjectRef, PyResult, VirtualMachine}; + use crate::{PyObjectRef, PyResult, VirtualMachine, signal}; use std::sync::atomic::{self, Ordering}; #[cfg(any(unix, windows))] diff --git a/vm/src/stdlib/sre.rs b/vm/src/stdlib/sre.rs index 8442002fa5..7d620c13d9 100644 --- a/vm/src/stdlib/sre.rs +++ b/vm/src/stdlib/sre.rs @@ -3,7 +3,8 @@ pub(crate) use _sre::make_module; #[pymodule] mod _sre { use crate::{ - atomic_func, + Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, + TryFromObject, VirtualMachine, atomic_func, builtins::{ PyCallableIterator, PyDictRef, PyGenericAlias, PyInt, PyList, PyListRef, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef, @@ -14,16 +15,14 @@ mod _sre { protocol::{PyBuffer, PyCallable, PyMappingMethods}, stdlib::sys, types::{AsMapping, Comparable, Hashable, Representable}, - Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromBorrowedObject, - TryFromObject, VirtualMachine, }; use core::str; use crossbeam_utils::atomic::AtomicCell; use itertools::Itertools; use num_traits::ToPrimitive; use rustpython_sre_engine::{ - string::{lower_ascii, lower_unicode, upper_unicode}, Request, SearchIter, SreFlag, State, StrDrive, + string::{lower_ascii, lower_unicode, upper_unicode}, }; #[pyattr] diff --git a/vm/src/stdlib/string.rs b/vm/src/stdlib/string.rs index cedff92d96..8a8a182732 100644 --- a/vm/src/stdlib/string.rs +++ b/vm/src/stdlib/string.rs @@ -7,10 +7,10 @@ pub(crate) use _string::make_module; mod _string { use crate::common::ascii; use crate::{ + PyObjectRef, PyResult, VirtualMachine, builtins::{PyList, PyStrRef}, convert::ToPyException, convert::ToPyObject, - PyObjectRef, PyResult, VirtualMachine, }; use rustpython_format::{ FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate, diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 10d79e9a8b..13a4105111 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -3,7 +3,7 @@ pub(crate) use symtable::make_module; #[pymodule] mod symtable { use crate::{ - builtins::PyStrRef, compiler, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyStrRef, compiler, }; use rustpython_codegen::symboltable::{ Symbol, SymbolFlags, SymbolScope, SymbolTable, SymbolTableType, diff --git a/vm/src/stdlib/sys.rs b/vm/src/stdlib/sys.rs index 59414b5fdd..dfaab20f2a 100644 --- a/vm/src/stdlib/sys.rs +++ b/vm/src/stdlib/sys.rs @@ -1,10 +1,11 @@ -use crate::{builtins::PyModule, convert::ToPyObject, Py, PyResult, VirtualMachine}; +use crate::{Py, PyResult, VirtualMachine, builtins::PyModule, convert::ToPyObject}; -pub(crate) use sys::{UnraisableHookArgs, __module_def, DOC, MAXSIZE, MULTIARCH}; +pub(crate) use sys::{__module_def, DOC, MAXSIZE, MULTIARCH, UnraisableHookArgs}; #[pymodule] mod sys { use crate::{ + AsObject, PyObject, PyObjectRef, PyRef, PyRefExact, PyResult, builtins::{ PyBaseExceptionRef, PyDictRef, PyNamespace, PyStr, PyStrRef, PyTupleRef, PyTypeRef, }, @@ -19,7 +20,6 @@ mod sys { types::PyStructSequence, version, vm::{Settings, VirtualMachine}, - AsObject, PyObject, PyObjectRef, PyRef, PyRefExact, PyResult, }; use num_traits::ToPrimitive; use std::{ @@ -85,11 +85,7 @@ mod sys { #[pyattr] fn default_prefix(_vm: &VirtualMachine) -> &'static str { // TODO: the windows one doesn't really make sense - if cfg!(windows) { - "C:" - } else { - "/usr/local" - } + if cfg!(windows) { "C:" } else { "/usr/local" } } #[pyattr] fn prefix(vm: &VirtualMachine) -> &'static str { @@ -574,9 +570,11 @@ mod sys { if vm.is_none(unraisable.exc_type.as_object()) { // TODO: early return, but with what error? } - assert!(unraisable - .exc_type - .fast_issubclass(vm.ctx.exceptions.base_exception_type)); + assert!( + unraisable + .exc_type + .fast_issubclass(vm.ctx.exceptions.base_exception_type) + ); // TODO: print module name and qualname diff --git a/vm/src/stdlib/sysconfigdata.rs b/vm/src/stdlib/sysconfigdata.rs index 929227ac11..90e46b83b9 100644 --- a/vm/src/stdlib/sysconfigdata.rs +++ b/vm/src/stdlib/sysconfigdata.rs @@ -2,7 +2,7 @@ pub(crate) use _sysconfigdata::make_module; #[pymodule] pub(crate) mod _sysconfigdata { - use crate::{builtins::PyDictRef, convert::ToPyObject, stdlib::sys::MULTIARCH, VirtualMachine}; + use crate::{VirtualMachine, builtins::PyDictRef, convert::ToPyObject, stdlib::sys::MULTIARCH}; #[pyattr] fn build_time_vars(vm: &VirtualMachine) -> PyDictRef { diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index 63e66474d1..bca7930437 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -1,20 +1,20 @@ //! Implementation of the _thread module #[cfg_attr(target_arch = "wasm32", allow(unused_imports))] -pub(crate) use _thread::{make_module, RawRMutex}; +pub(crate) use _thread::{RawRMutex, make_module}; #[pymodule] pub(crate) mod _thread { use crate::{ + AsObject, Py, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyDictRef, PyStr, PyTupleRef, PyTypeRef}, convert::ToPyException, function::{ArgCallable, Either, FuncArgs, KwArgs, OptionalArg, PySetterValue}, types::{Constructor, GetAttr, Representable, SetAttr}, - AsObject, Py, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use parking_lot::{ - lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex}, RawMutex, RawThreadId, + lock_api::{RawMutex as RawMutexT, RawMutexTimed, RawReentrantMutex}, }; use std::{cell::RefCell, fmt, thread, time::Duration}; use thread_local::ThreadLocal; diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 3c87550f93..37a518e504 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -2,7 +2,7 @@ // See also: // https://docs.python.org/3/library/time.html -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; pub use decl::time; @@ -33,14 +33,14 @@ unsafe extern "C" { #[pymodule(name = "time", with(platform))] mod decl { use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyStrRef, PyTypeRef}, function::{Either, FuncArgs, OptionalArg}, types::PyStructSequence, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use chrono::{ - naive::{NaiveDate, NaiveDateTime, NaiveTime}, DateTime, Datelike, Timelike, + naive::{NaiveDate, NaiveDateTime, NaiveTime}, }; use std::time::Duration; #[cfg(target_env = "msvc")] @@ -509,9 +509,9 @@ mod platform { use super::decl::{SEC_TO_NS, US_TO_NS}; #[cfg_attr(target_os = "macos", allow(unused_imports))] use crate::{ + PyObject, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, builtins::{PyNamespace, PyStrRef}, convert::IntoPyException, - PyObject, PyRef, PyResult, TryFromBorrowedObject, VirtualMachine, }; use nix::{sys::time::TimeSpec, time::ClockId}; use std::time::Duration; @@ -721,7 +721,7 @@ mod platform { target_os = "openbsd", ))] pub(super) fn get_process_time(vm: &VirtualMachine) -> PyResult { - use nix::sys::resource::{getrusage, UsageWho}; + use nix::sys::resource::{UsageWho, getrusage}; fn from_timeval(tv: libc::timeval, vm: &VirtualMachine) -> PyResult { (|tv: libc::timeval| { let t = tv.tv_sec.checked_mul(SEC_TO_NS)?; @@ -743,11 +743,11 @@ mod platform { #[cfg(windows)] #[pymodule] mod platform { - use super::decl::{time_muldiv, MS_TO_NS, SEC_TO_NS}; + use super::decl::{MS_TO_NS, SEC_TO_NS, time_muldiv}; use crate::{ + PyRef, PyResult, VirtualMachine, builtins::{PyNamespace, PyStrRef}, stdlib::os::errno_err, - PyRef, PyResult, VirtualMachine, }; use std::time::Duration; use windows_sys::Win32::{ diff --git a/vm/src/stdlib/typing.rs b/vm/src/stdlib/typing.rs index 29ce516b14..c266e811ca 100644 --- a/vm/src/stdlib/typing.rs +++ b/vm/src/stdlib/typing.rs @@ -3,9 +3,9 @@ pub(crate) use _typing::make_module; #[pymodule] pub(crate) mod _typing { use crate::{ - builtins::{pystr::AsPyStr, PyGenericAlias, PyTupleRef, PyTypeRef}, - function::IntoFuncArgs, PyObjectRef, PyPayload, PyResult, VirtualMachine, + builtins::{PyGenericAlias, PyTupleRef, PyTypeRef, pystr::AsPyStr}, + function::IntoFuncArgs, }; pub(crate) fn _call_typing_func_object<'a>( diff --git a/vm/src/stdlib/warnings.rs b/vm/src/stdlib/warnings.rs index be5ad8131e..a8ffee4579 100644 --- a/vm/src/stdlib/warnings.rs +++ b/vm/src/stdlib/warnings.rs @@ -1,6 +1,6 @@ pub(crate) use _warnings::make_module; -use crate::{builtins::PyType, Py, PyResult, VirtualMachine}; +use crate::{Py, PyResult, VirtualMachine, builtins::PyType}; pub fn warn( category: &Py, @@ -20,9 +20,9 @@ pub fn warn( #[pymodule] mod _warnings { use crate::{ + PyResult, VirtualMachine, builtins::{PyStrRef, PyTypeRef}, function::OptionalArg, - PyResult, VirtualMachine, }; #[derive(FromArgs)] diff --git a/vm/src/stdlib/weakref.rs b/vm/src/stdlib/weakref.rs index 3ef0de6155..7d8924ff52 100644 --- a/vm/src/stdlib/weakref.rs +++ b/vm/src/stdlib/weakref.rs @@ -9,8 +9,8 @@ pub(crate) use _weakref::make_module; #[pymodule] mod _weakref { use crate::{ - builtins::{PyDictRef, PyTypeRef, PyWeak}, PyObjectRef, PyResult, VirtualMachine, + builtins::{PyDictRef, PyTypeRef, PyWeak}, }; #[pyattr(name = "ref")] diff --git a/vm/src/stdlib/winapi.rs b/vm/src/stdlib/winapi.rs index 6cf8c45bfe..c1edb2739e 100644 --- a/vm/src/stdlib/winapi.rs +++ b/vm/src/stdlib/winapi.rs @@ -4,18 +4,18 @@ pub(crate) use _winapi::make_module; #[pymodule] mod _winapi { use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, builtins::PyStrRef, common::windows::ToWideString, convert::{ToPyException, ToPyResult}, function::{ArgMapping, ArgSequence, OptionalArg}, stdlib::os::errno_err, windows::WindowsSysResult, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use std::ptr::{null, null_mut}; use windows::{ - core::PCWSTR, Win32::Foundation::{HANDLE, HINSTANCE, MAX_PATH}, + core::PCWSTR, }; use windows_sys::Win32::Foundation::{BOOL, HANDLE as RAW_HANDLE}; diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index f25ca0b960..b0dbbfceec 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -1,6 +1,6 @@ #![allow(non_snake_case)] -use crate::{builtins::PyModule, PyRef, VirtualMachine}; +use crate::{PyRef, VirtualMachine, builtins::PyModule}; pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { let module = winreg::make_module(vm); @@ -29,10 +29,10 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef { mod winreg { use crate::common::lock::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::{ - builtins::PyStrRef, convert::ToPyException, PyObjectRef, PyPayload, PyRef, PyResult, - TryFromObject, VirtualMachine, + PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::PyStrRef, + convert::ToPyException, }; - use ::winreg::{enums::RegType, RegKey, RegValue}; + use ::winreg::{RegKey, RegValue, enums::RegType}; use std::mem::ManuallyDrop; use std::{ffi::OsStr, io}; use windows_sys::Win32::Foundation; diff --git a/vm/src/suggestion.rs b/vm/src/suggestion.rs index d46630a651..2bc9992d43 100644 --- a/vm/src/suggestion.rs +++ b/vm/src/suggestion.rs @@ -1,10 +1,10 @@ use crate::{ + AsObject, Py, PyObjectRef, VirtualMachine, builtins::{PyStr, PyStrRef}, exceptions::types::PyBaseExceptionRef, sliceable::SliceableSequenceOp, - AsObject, Py, PyObjectRef, VirtualMachine, }; -use rustpython_common::str::levenshtein::{levenshtein_distance, MOVE_COST}; +use rustpython_common::str::levenshtein::{MOVE_COST, levenshtein_distance}; use std::iter::ExactSizeIterator; const MAX_CANDIDATE_ITEMS: usize = 750; @@ -52,10 +52,8 @@ pub fn offer_suggestions(exc: &PyBaseExceptionRef, vm: &VirtualMachine) -> Optio calculate_suggestions(vm.dir(Some(obj)).ok()?.borrow_vec().iter(), &name) } else if exc.class().is(vm.ctx.exceptions.name_error) { let name = exc.as_object().get_attr("name", vm).unwrap(); - let mut tb = exc.traceback()?; - for traceback in tb.iter() { - tb = traceback; - } + let tb = exc.traceback()?; + let tb = tb.iter().last().unwrap_or(tb); let varnames = tb.frame.code.clone().co_varnames(vm); if let Some(suggestions) = calculate_suggestions(varnames.iter(), &name) { diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index 75f113977d..de651580d9 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -1,5 +1,6 @@ use crate::{ - builtins::{type_::PointerSlot, PyInt, PyStr, PyStrInterned, PyStrRef, PyType, PyTypeRef}, + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, + builtins::{PyInt, PyStr, PyStrInterned, PyStrRef, PyType, PyTypeRef, type_::PointerSlot}, bytecode::ComparisonOperator, common::hash::PyHash, convert::{ToPyObject, ToPyResult}, @@ -12,7 +13,6 @@ use crate::{ PyNumberSlots, PySequence, PySequenceMethods, }, vm::Context, - AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; use crossbeam_utils::atomic::AtomicCell; use malachite_bigint::BigInt; diff --git a/vm/src/types/structseq.rs b/vm/src/types/structseq.rs index 516e2085af..a0b445ce7d 100644 --- a/vm/src/types/structseq.rs +++ b/vm/src/types/structseq.rs @@ -1,8 +1,8 @@ use crate::{ + AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyTuple, PyTupleRef, PyType}, class::{PyClassImpl, StaticType}, vm::Context, - AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; #[pyclass] diff --git a/vm/src/types/zoo.rs b/vm/src/types/zoo.rs index 492b584e29..0d39648514 100644 --- a/vm/src/types/zoo.rs +++ b/vm/src/types/zoo.rs @@ -1,4 +1,5 @@ use crate::{ + Py, builtins::{ asyncgenerator, bool_, builtin_func, bytearray, bytes, classmethod, code, complex, coroutine, descriptor, dict, enumerate, filter, float, frame, function, generator, @@ -10,7 +11,6 @@ use crate::{ }, class::StaticType, vm::Context, - Py, }; /// Holder of references to builtin types. diff --git a/vm/src/utils.rs b/vm/src/utils.rs index c7ab7148d1..e2bc993686 100644 --- a/vm/src/utils.rs +++ b/vm/src/utils.rs @@ -1,8 +1,8 @@ use crate::{ + PyObjectRef, PyResult, VirtualMachine, builtins::PyStr, convert::{ToPyException, ToPyObject}, exceptions::cstring_error, - PyObjectRef, PyResult, VirtualMachine, }; pub fn hash_iter<'a, I: IntoIterator>( diff --git a/vm/src/version.rs b/vm/src/version.rs index 3b6d9aa0ea..8c42866a64 100644 --- a/vm/src/version.rs +++ b/vm/src/version.rs @@ -1,7 +1,7 @@ /* Several function to retrieve version information. */ -use chrono::{prelude::DateTime, Local}; +use chrono::{Local, prelude::DateTime}; use std::time::{Duration, UNIX_EPOCH}; // = 3.13.0alpha diff --git a/vm/src/vm/compile.rs b/vm/src/vm/compile.rs index b7c888ab10..a14e986dac 100644 --- a/vm/src/vm/compile.rs +++ b/vm/src/vm/compile.rs @@ -1,9 +1,9 @@ use crate::{ + AsObject, PyObjectRef, PyRef, PyResult, VirtualMachine, builtins::{PyCode, PyDictRef}, compiler::{self, CompileError, CompileOpts}, convert::TryFromObject, scope::Scope, - AsObject, PyObjectRef, PyRef, PyResult, VirtualMachine, }; impl VirtualMachine { diff --git a/vm/src/vm/context.rs b/vm/src/vm/context.rs index 9f031f01ce..54605704a5 100644 --- a/vm/src/vm/context.rs +++ b/vm/src/vm/context.rs @@ -1,6 +1,9 @@ use crate::{ + PyResult, VirtualMachine, builtins::{ - bytes, + PyBaseException, PyBytes, PyComplex, PyDict, PyDictRef, PyEllipsis, PyFloat, PyFrozenSet, + PyInt, PyIntRef, PyList, PyListRef, PyNone, PyNotImplemented, PyStr, PyStrInterned, + PyTuple, PyTupleRef, PyType, PyTypeRef, bytes, code::{self, PyCode}, descriptor::{ MemberGetter, MemberKind, MemberSetter, MemberSetterFunc, PyDescriptorOwned, @@ -9,9 +12,6 @@ use crate::{ getset::PyGetSet, object, pystr, type_::PyAttributes, - PyBaseException, PyBytes, PyComplex, PyDict, PyDictRef, PyEllipsis, PyFloat, PyFrozenSet, - PyInt, PyIntRef, PyList, PyListRef, PyNone, PyNotImplemented, PyStr, PyStrInterned, - PyTuple, PyTupleRef, PyType, PyTypeRef, }, class::{PyClassImpl, StaticType}, common::rc::PyRc, @@ -23,7 +23,6 @@ use crate::{ intern::{InternableString, MaybeInternedString, StringPool}, object::{Py, PyObjectPayload, PyObjectRef, PyPayload, PyRef}, types::{PyTypeFlags, PyTypeSlots, TypeZoo}, - PyResult, VirtualMachine, }; use malachite_bigint::BigInt; use num_complex::Complex64; diff --git a/vm/src/vm/interpreter.rs b/vm/src/vm/interpreter.rs index af28ad87ab..a375dbedc1 100644 --- a/vm/src/vm/interpreter.rs +++ b/vm/src/vm/interpreter.rs @@ -1,5 +1,5 @@ -use super::{setting::Settings, thread, Context, VirtualMachine}; -use crate::{stdlib::atexit, vm::PyBaseExceptionRef, PyResult}; +use super::{Context, VirtualMachine, setting::Settings, thread}; +use crate::{PyResult, stdlib::atexit, vm::PyBaseExceptionRef}; use std::sync::atomic::Ordering; /// The general interface for the VM @@ -140,8 +140,8 @@ impl Interpreter { mod tests { use super::*; use crate::{ - builtins::{int, PyStr}, PyObjectRef, + builtins::{PyStr, int}, }; use malachite_bigint::ToBigInt; diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 3d3351055f..05ac245a0a 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -15,12 +15,13 @@ mod vm_object; mod vm_ops; use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, builtins::{ + PyBaseExceptionRef, PyDictRef, PyInt, PyList, PyModule, PyStr, PyStrInterned, PyStrRef, + PyTypeRef, code::PyCode, pystr::AsPyStr, tuple::{PyTuple, PyTupleTyped}, - PyBaseExceptionRef, PyDictRef, PyInt, PyList, PyModule, PyStr, PyStrInterned, PyStrRef, - PyTypeRef, }, codecs::CodecsRegistry, common::{hash::HashSecret, lock::PyMutex, rc::PyRc}, @@ -33,12 +34,11 @@ use crate::{ scope::Scope, signal, stdlib, warn::WarningsState, - AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, }; use crossbeam_utils::atomic::AtomicCell; #[cfg(unix)] use nix::{ - sys::signal::{kill, sigaction, SaFlags, SigAction, SigSet, Signal::SIGINT}, + sys::signal::{SaFlags, SigAction, SigSet, Signal::SIGINT, kill, sigaction}, unistd::getpid, }; use std::sync::atomic::AtomicBool; @@ -356,7 +356,9 @@ impl VirtualMachine { if self.state.settings.allow_external_library && cfg!(feature = "rustpython-compiler") { if let Err(e) = import::init_importlib_package(self, importlib) { - eprintln!("importlib initialization failed. This is critical for many complicated packages."); + eprintln!( + "importlib initialization failed. This is critical for many complicated packages." + ); self.print_exception(e); } } diff --git a/vm/src/vm/vm_new.rs b/vm/src/vm/vm_new.rs index ed0cd5be3f..bd42396299 100644 --- a/vm/src/vm/vm_new.rs +++ b/vm/src/vm/vm_new.rs @@ -1,15 +1,15 @@ use crate::{ + AsObject, Py, PyObject, PyObjectRef, PyRef, builtins::{ + PyBaseException, PyBaseExceptionRef, PyDictRef, PyModule, PyStrRef, PyType, PyTypeRef, builtin_func::PyNativeFunction, descriptor::PyMethodDescriptor, tuple::{IntoPyTuple, PyTupleRef}, - PyBaseException, PyBaseExceptionRef, PyDictRef, PyModule, PyStrRef, PyType, PyTypeRef, }, convert::ToPyObject, function::{IntoPyNativeFn, PyMethodFlags}, scope::Scope, vm::VirtualMachine, - AsObject, Py, PyObject, PyObjectRef, PyRef, }; /// Collection of object creation helpers diff --git a/vm/src/vm/vm_object.rs b/vm/src/vm/vm_object.rs index b687eea34c..103078272d 100644 --- a/vm/src/vm/vm_object.rs +++ b/vm/src/vm/vm_object.rs @@ -1,6 +1,6 @@ use super::PyMethod; use crate::{ - builtins::{pystr::AsPyStr, PyBaseExceptionRef, PyList, PyStrInterned}, + builtins::{PyBaseExceptionRef, PyList, PyStrInterned, pystr::AsPyStr}, function::IntoFuncArgs, identifier, object::{AsObject, PyObject, PyObjectRef, PyResult}, @@ -85,11 +85,7 @@ impl VirtualMachine { obj.is(&self.ctx.none) } pub fn option_if_none(&self, obj: PyObjectRef) -> Option { - if self.is_none(&obj) { - None - } else { - Some(obj) - } + if self.is_none(&obj) { None } else { Some(obj) } } pub fn unwrap_or_none(&self, obj: Option) -> PyObjectRef { obj.unwrap_or_else(|| self.ctx.none()) diff --git a/vm/src/vm/vm_ops.rs b/vm/src/vm/vm_ops.rs index 3aa4144190..09f849a1a1 100644 --- a/vm/src/vm/vm_ops.rs +++ b/vm/src/vm/vm_ops.rs @@ -114,7 +114,7 @@ impl VirtualMachine { Ok(None) } else { Err(e) - } + }; } }; let hint = result diff --git a/vm/src/warn.rs b/vm/src/warn.rs index ab316c8559..b2055225a0 100644 --- a/vm/src/warn.rs +++ b/vm/src/warn.rs @@ -1,11 +1,11 @@ use crate::{ + AsObject, Context, Py, PyObjectRef, PyResult, VirtualMachine, builtins::{ PyDict, PyDictRef, PyListRef, PyStr, PyStrInterned, PyStrRef, PyTuple, PyTupleRef, PyTypeRef, }, convert::{IntoObject, TryFromObject}, types::PyComparisonOp, - AsObject, Context, Py, PyObjectRef, PyResult, VirtualMachine, }; pub struct WarningsState { @@ -17,15 +17,16 @@ pub struct WarningsState { impl WarningsState { fn create_filter(ctx: &Context) -> PyListRef { - ctx.new_list(vec![ctx - .new_tuple(vec![ + ctx.new_list(vec![ + ctx.new_tuple(vec![ ctx.new_str("__main__").into(), ctx.types.none_type.as_object().to_owned(), ctx.exceptions.warning.as_object().to_owned(), ctx.new_str("ACTION").into(), ctx.new_int(0).into(), ]) - .into()]) + .into(), + ]) } pub fn init_state(ctx: &Context) -> WarningsState { diff --git a/vm/src/windows.rs b/vm/src/windows.rs index f98bb1de63..f4f4dad0b3 100644 --- a/vm/src/windows.rs +++ b/vm/src/windows.rs @@ -1,11 +1,11 @@ use crate::common::fileutils::{ - windows::{get_file_information_by_name, FILE_INFO_BY_NAME_CLASS}, StatStruct, + windows::{FILE_INFO_BY_NAME_CLASS, get_file_information_by_name}, }; use crate::{ + PyObjectRef, PyResult, TryFromObject, VirtualMachine, convert::{ToPyObject, ToPyResult}, stdlib::os::errno_err, - PyObjectRef, PyResult, TryFromObject, VirtualMachine, }; use std::{ffi::OsStr, time::SystemTime}; use windows::Win32::Foundation::HANDLE; @@ -139,7 +139,7 @@ fn file_id(path: &OsStr) -> std::io::Result { use windows_sys::Win32::{ Foundation::HANDLE, Storage::FileSystem::{ - GetFileInformationByHandle, BY_HANDLE_FILE_INFORMATION, FILE_FLAG_BACKUP_SEMANTICS, + BY_HANDLE_FILE_INFORMATION, FILE_FLAG_BACKUP_SEMANTICS, GetFileInformationByHandle, }, }; diff --git a/vm/sre_engine/benches/benches.rs b/vm/sre_engine/benches/benches.rs index 915d568333..ee49b036de 100644 --- a/vm/sre_engine/benches/benches.rs +++ b/vm/sre_engine/benches/benches.rs @@ -1,6 +1,6 @@ use rustpython_sre_engine::{Request, State, StrDrive}; -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; struct Pattern { pattern: &'static str, diff --git a/vm/sre_engine/src/engine.rs b/vm/sre_engine/src/engine.rs index 77f4ccdf36..3425da3371 100644 --- a/vm/sre_engine/src/engine.rs +++ b/vm/sre_engine/src/engine.rs @@ -5,7 +5,7 @@ use crate::string::{ is_uni_word, is_word, lower_ascii, lower_locate, lower_unicode, upper_locate, upper_unicode, }; -use super::{SreAtCode, SreCatCode, SreInfo, SreOpcode, StrDrive, StringCursor, MAXREPEAT}; +use super::{MAXREPEAT, SreAtCode, SreCatCode, SreInfo, SreOpcode, StrDrive, StringCursor}; use optional::Optioned; use std::{convert::TryFrom, ptr::null}; diff --git a/vm/sre_engine/src/lib.rs b/vm/sre_engine/src/lib.rs index fd9f367dc6..08c21de9df 100644 --- a/vm/sre_engine/src/lib.rs +++ b/vm/sre_engine/src/lib.rs @@ -2,7 +2,7 @@ pub mod constants; pub mod engine; pub mod string; -pub use constants::{SreAtCode, SreCatCode, SreFlag, SreInfo, SreOpcode, SRE_MAGIC}; +pub use constants::{SRE_MAGIC, SreAtCode, SreCatCode, SreFlag, SreInfo, SreOpcode}; pub use engine::{Request, SearchIter, State}; pub use string::{StrDrive, StringCursor}; diff --git a/vm/sre_engine/src/string.rs b/vm/sre_engine/src/string.rs index b5a2470f52..77e0f3e772 100644 --- a/vm/sre_engine/src/string.rs +++ b/vm/sre_engine/src/string.rs @@ -157,8 +157,8 @@ impl StrDrive for &str { #[inline] unsafe fn next_code_point(ptr: &mut *const u8) -> u32 { // Decode UTF-8 - let x = **ptr; - *ptr = ptr.offset(1); + let x = unsafe { **ptr }; + *ptr = unsafe { ptr.offset(1) }; if x < 128 { return x as u32; @@ -170,16 +170,16 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 { let init = utf8_first_byte(x, 2); // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - let y = **ptr; - *ptr = ptr.offset(1); + let y = unsafe { **ptr }; + *ptr = unsafe { ptr.offset(1) }; let mut ch = utf8_acc_cont_byte(init, y); if x >= 0xE0 { // [[x y z] w] case // 5th bit in 0xE0 .. 0xEF is always clear, so `init` is still valid // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - let z = **ptr; - *ptr = ptr.offset(1); + let z = unsafe { **ptr }; + *ptr = unsafe { ptr.offset(1) }; let y_z = utf8_acc_cont_byte((y & CONT_MASK) as u32, z); ch = (init << 12) | y_z; if x >= 0xF0 { @@ -187,8 +187,8 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 { // use only the lower 3 bits of `init` // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - let w = **ptr; - *ptr = ptr.offset(1); + let w = unsafe { **ptr }; + *ptr = unsafe { ptr.offset(1) }; ch = ((init & 7) << 18) | utf8_acc_cont_byte(y_z, w); } } @@ -205,8 +205,8 @@ unsafe fn next_code_point(ptr: &mut *const u8) -> u32 { #[inline] unsafe fn next_code_point_reverse(ptr: &mut *const u8) -> u32 { // Decode UTF-8 - *ptr = ptr.offset(-1); - let w = match **ptr { + *ptr = unsafe { ptr.offset(-1) }; + let w = match unsafe { **ptr } { next_byte if next_byte < 128 => return next_byte as u32, back_byte => back_byte, }; @@ -216,20 +216,20 @@ unsafe fn next_code_point_reverse(ptr: &mut *const u8) -> u32 { let mut ch; // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - *ptr = ptr.offset(-1); - let z = **ptr; + *ptr = unsafe { ptr.offset(-1) }; + let z = unsafe { **ptr }; ch = utf8_first_byte(z, 2); if utf8_is_cont_byte(z) { // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - *ptr = ptr.offset(-1); - let y = **ptr; + *ptr = unsafe { ptr.offset(-1) }; + let y = unsafe { **ptr }; ch = utf8_first_byte(y, 3); if utf8_is_cont_byte(y) { // SAFETY: `bytes` produces an UTF-8-like string, // so the iterator must produce a value here. - *ptr = ptr.offset(-1); - let x = **ptr; + *ptr = unsafe { ptr.offset(-1) }; + let x = unsafe { **ptr }; ch = utf8_first_byte(x, 4); ch = utf8_acc_cont_byte(ch, y); } diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index 86a3ea3ab3..f8d1b2ebc3 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -7,14 +7,14 @@ mod _browser { use crate::{convert, js_module::PyPromise, vm_class::weak_vm, wasm_builtins::window}; use js_sys::Promise; use rustpython_vm::{ + PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{PyDictRef, PyStrRef}, class::PyClassImpl, convert::ToPyObject, function::{ArgCallable, OptionalArg}, import::import_source, - PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, }; - use wasm_bindgen::{prelude::*, JsCast}; + use wasm_bindgen::{JsCast, prelude::*}; use wasm_bindgen_futures::JsFuture; enum FetchResponseFormat { diff --git a/wasm/lib/src/convert.rs b/wasm/lib/src/convert.rs index 0bf1d21c95..d4fb068e6c 100644 --- a/wasm/lib/src/convert.rs +++ b/wasm/lib/src/convert.rs @@ -1,17 +1,18 @@ #![allow(clippy::empty_docs)] // TODO: remove it later. false positive by wasm-bindgen generated code use crate::js_module; -use crate::vm_class::{stored_vm_from_wasm, WASMVirtualMachine}; +use crate::vm_class::{WASMVirtualMachine, stored_vm_from_wasm}; use js_sys::{Array, ArrayBuffer, Object, Promise, Reflect, SyntaxError, Uint8Array}; -use rustpython_parser::{lexer::LexicalErrorType, ParseErrorType}; +use rustpython_parser::{ParseErrorType, lexer::LexicalErrorType}; use rustpython_vm::{ + AsObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, builtins::PyBaseExceptionRef, compiler::{CompileError, CompileErrorType}, exceptions, function::{ArgBytesLike, FuncArgs}, - py_serde, AsObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, + py_serde, }; -use wasm_bindgen::{closure::Closure, prelude::*, JsCast}; +use wasm_bindgen::{JsCast, closure::Closure, prelude::*}; #[wasm_bindgen(inline_js = r" export class PyError extends Error { diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index f0c5378c35..e25499df4d 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -5,21 +5,21 @@ use rustpython_vm::VirtualMachine; mod _js { use crate::{ convert, - vm_class::{stored_vm_from_wasm, WASMVirtualMachine}, + vm_class::{WASMVirtualMachine, stored_vm_from_wasm}, weak_vm, }; use js_sys::{Array, Object, Promise, Reflect}; use rustpython_vm::{ + Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::{PyBaseExceptionRef, PyFloat, PyStrRef, PyType, PyTypeRef}, convert::{IntoObject, ToPyObject}, function::{ArgCallable, OptionalArg, OptionalOption, PosArgs}, protocol::PyIterReturn, types::{IterNext, Representable, SelfIter}, - Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine, }; use std::{cell, fmt, future}; - use wasm_bindgen::{closure::Closure, prelude::*, JsCast}; - use wasm_bindgen_futures::{future_to_promise, JsFuture}; + use wasm_bindgen::{JsCast, closure::Closure, prelude::*}; + use wasm_bindgen_futures::{JsFuture, future_to_promise}; #[wasm_bindgen(inline_js = " export function has_prop(target, prop) { return prop in Object(target); } diff --git a/wasm/lib/src/vm_class.rs b/wasm/lib/src/vm_class.rs index 4ba5760511..c04877f7e3 100644 --- a/wasm/lib/src/vm_class.rs +++ b/wasm/lib/src/vm_class.rs @@ -5,10 +5,10 @@ use crate::{ }; use js_sys::{Object, TypeError}; use rustpython_vm::{ + Interpreter, PyObjectRef, PyPayload, PyRef, PyResult, Settings, VirtualMachine, builtins::{PyModule, PyWeak}, compiler::Mode, scope::Scope, - Interpreter, PyObjectRef, PyPayload, PyRef, PyResult, Settings, VirtualMachine, }; use std::{ cell::RefCell, diff --git a/wasm/lib/src/wasm_builtins.rs b/wasm/lib/src/wasm_builtins.rs index 59d7880af4..79423fc250 100644 --- a/wasm/lib/src/wasm_builtins.rs +++ b/wasm/lib/src/wasm_builtins.rs @@ -4,7 +4,7 @@ //! desktop. //! Implements functions listed here: https://docs.python.org/3/library/builtins.html. -use rustpython_vm::{builtins::PyStrRef, PyObjectRef, PyRef, PyResult, VirtualMachine}; +use rustpython_vm::{PyObjectRef, PyRef, PyResult, VirtualMachine, builtins::PyStrRef}; use web_sys::{self, console}; pub(crate) fn window() -> web_sys::Window {