8000 2024 edition formatting · RustPython/RustPython@b870b0e · GitHub
[go: up one dir, main page]

Skip to content

Commit b870b0e

Browse files
committed
2024 edition formatting
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent df2354f commit b870b0e

File tree

214 files changed

+644
-744
lines changed

Some content is hidden

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

214 files changed

+644
-744
lines changed

benches/execution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use criterion::measurement::WallTime;
22
use criterion::{
3-
black_box, criterion_group, criterion_main, Bencher, BenchmarkGroup, BenchmarkId, Criterion,
4-
Throughput,
3+
Bencher, BenchmarkGroup, BenchmarkId, Criterion, Throughput, black_box, criterion_group,
4+
criterion_main,
55
};
66
use rustpython_compiler::Mode;
7-
use rustpython_parser::ast;
87
use rustpython_parser::Parse;
8+
use rustpython_parser::ast;
99
use rustpython_vm::{Interpreter, PyResult, Settings};
1010
use std::collections::HashMap;
1111
use std::path::Path;

benches/microbenchmarks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{
2-
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
3-
Criterion, Throughput,
2+
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main,
3+
measurement::WallTime,
44
};
55
use pyo3::types::PyAnyMethods;
66
use rustpython_compiler::Mode;

common/src/fileutils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub use libc::stat as StatStruct;
66

77
#[cfg(windows)]
8-
pub use windows::{fstat, StatStruct};
8+
pub use windows::{StatStruct, fstat};
99

1010
#[cfg(not(windows))]
1111
pub fn fstat(fd: libc::c_int) -> std::io::Result<StatStruct> {
@@ -28,19 +28,19 @@ pub mod windows {
2828
use std::ffi::{CString, OsStr, OsString};
2929
use std::os::windows::ffi::OsStrExt;
3030
use std::sync::OnceLock;
31-
use windows_sys::core::PCWSTR;
3231
use windows_sys::Win32::Foundation::{
33-
FreeLibrary, SetLastError, BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME,
34-
HANDLE, INVALID_HANDLE_VALUE,
32+
BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME, FreeLibrary, HANDLE,
33+
INVALID_HANDLE_VALUE, SetLastError,
3534
};
3635
use windows_sys::Win32::Storage::FileSystem::{
37-
FileBasicInfo, FileIdInfo, GetFileInformationByHandle, GetFileInformationByHandleEx,
38-
GetFileType, BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY,
36+
BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY,
3937
FILE_ATTRIBUTE_REPARSE_POINT, FILE_BASIC_INFO, FILE_ID_INFO, FILE_TYPE_CHAR,
40-
FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN,
38+
FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN, FileBasicInfo, FileIdInfo,
39+
GetFileInformationByHandle, GetFileInformationByHandleEx, GetFileType,
4140
};
4241
use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW};
4342
use windows_sys::Win32::System::SystemServices::IO_REPARSE_TAG_SYMLINK;
43+
use windows_sys::core::PCWSTR;
4444

4545
pub const S_IFIFO: libc::c_int = 0o010000;
4646
pub const S_IFLNK: libc::c_int = 0o120000;

common/src/float_ops.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
6464
}
6565

6666
pub fn div(v1: f64, v2: f64) -> Option<f64> {
67-
if v2 != 0.0 {
68-
Some(v1 / v2)
69-
} else {
70-
None
71-
}
67+
if v2 != 0.0 { Some(v1 / v2) } else { None }
7268
}
7369

7470
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
@@ -125,11 +121,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 {
125121
let b = x.to_bits();
126122
let bits = if (y > x) == (x > 0.0) { b + 1 } else { b - 1 };
127123
let ret = f64::from_bits(bits);
128-
if ret == 0.0 {
129-
ret.copysign(x)
130-
} else {
131-
ret
132-
}
124+
if ret == 0.0 { ret.copysign(x) } else { ret }
133125
}
134126
}
135127

common/src/hash.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ pub fn hash_bigint(value: &BigInt) -> PyHash {
150150

151151
#[inline(always)]
152152
pub fn fix_sentinel(x: PyHash) -> PyHash {
153-
if x == SENTINEL {
154-
-2
155-
} else {
156-
x
157-
}
153+
if x == SENTINEL { -2 } else { x }
158154
}
159155

160156
#[inline]

common/src/str.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,7 @@ pub mod levenshtein {
241241
if b.is_ascii_uppercase() {
242242
b += b'a' - b'A';
243243
}
244-
if a == b {
245-
CASE_COST
246-
} else {
247-
MOVE_COST
248-
}
244+
if a == b { CASE_COST } else { MOVE_COST }
249245
}
250246

251247
pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize {

compiler/codegen/src/compile.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
#![deny(clippy::cast_possible_truncation)]
99

1010
use crate::{
11+
IndexSet,
1112
error::{CodegenError, CodegenErrorType},
1213
ir,
1314
symboltable::{self, SymbolFlags, SymbolScope, SymbolTable},
14-
IndexSet,
1515
};
1616
use itertools::Itertools;
1717
use num_complex::Complex64;
1818
use num_traits::ToPrimitive;
1919
use rustpython_ast::located::{self as located_ast, Located};
2020
use rustpython_compiler_core::{
21+
Mode,
2122
bytecode::{
2223
self, Arg as OpArgMarker, CodeObject, ComparisonOperator, ConstantData, Instruction, OpArg,
2324
OpArgType,
2425
},
25-
Mode,
2626
};
2727
use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
2828
use std::borrow::Cow;
@@ -975,7 +975,7 @@ impl Compiler {
975975
}
976976
}
977977
located_ast::Expr::BinOp(_) | located_ast::Expr::UnaryOp(_) => {
978-
return Err(self.error(CodegenErrorType::Delete("expression")))
978+
return Err(self.error(CodegenErrorType::Delete("expression")));
979979
}
980980
_ => return Err(self.error(CodegenErrorType::Delete(expression.python_name()))),
981981
}
@@ -1213,7 +1213,7 @@ impl Compiler {
12131213

12141214
if !finalbody.is_empty() {
12151215
emit!(self, Instruction::PopBlock); // pop excepthandler block
1216-
// We enter the finally block, without exception.
1216+
// We enter the finally block, without exception.
12171217
emit!(self, Instruction::EnterFinally);
12181218
}
12191219

@@ -3124,7 +3124,9 @@ impl Compiler {
31243124
| "with_statement" | "print_function" | "unicode_literals" | "generator_stop" => {}
31253125
"annotations" => self.future_annotations = true,
31263126
other => {
3127-
return Err(self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned())))
3127+
return Err(
3128+
self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned()))
3129+
);
31283130
}
31293131
}
31303132
}
@@ -3477,8 +3479,8 @@ impl ToU32 for usize {
34773479
#[cfg(test)]
34783480
mod tests {
34793481
use super::*;
3480-
use rustpython_parser::ast::Suite;
34813482
use rustpython_parser::Parse;
3483+
use rustpython_parser::ast::Suite;
34823484
use rustpython_parser_core::source_code::LinearLocator;
34833485

34843486
fn compile_exec(source: &str) -> CodeObject {

compiler/codegen/src/ir.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ impl CodeInfo {
199199
})
200200
.collect::<Box<[_]>>();
201201

202-
if found_cellarg {
203-
Some(cell2arg)
204-
} else {
205-
None
206-
}
202+
if found_cellarg { Some(cell2arg) } else { None }
207203
}
208204

209205
fn dce(&mut self) {

compiler/codegen/src/symboltable.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Inspirational file: https://github.com/python/cpython/blob/main/Python/symtable.
88
*/
99

1010
use crate::{
11-
error::{CodegenError, CodegenErrorType},
1211
IndexMap,
12+
error::{CodegenError, CodegenErrorType},
1313
};
1414
use bitflags::bitflags;
1515
use rustpython_ast::{self as ast, located::Located};
@@ -505,7 +505,10 @@ impl SymbolTableAnalyzer {
505505
// check if assignee is an iterator in top scope
506506
if parent_symbol.flags.contains(SymbolFlags::ITER) {
507507
return Err(SymbolTableError {
508-
error: format!("assignment expression cannot rebind comprehension iteration variable {}", symbol.name),
508+
error: format!(
509+
"assignment expression cannot rebind comprehension iteration variable {}",
510+
symbol.name
511+
),
509512
location: None,
510513
});
511514
}
@@ -1408,7 +1411,7 @@ impl SymbolTableBuilder {
14081411
return Err(SymbolTableError {
14091412
error: format!("cannot define nonlocal '{name}' at top level."),
14101413
location,
1411-
})
1414+
});
14121415
}
14131416
_ => {
14141417
// Ok!

compiler/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use rustpython_codegen::{compile, symboltable};
2-
use rustpython_parser::ast::{self as ast, fold::Fold, ConstantOptimizer};
2+
use rustpython_parser::ast::{self as ast, ConstantOptimizer, fold::Fold};
33

44
pub use rustpython_codegen::compile::CompileOpts;
5-
pub use rustpython_compiler_core::{bytecode::CodeObject, Mode};
6-
pub use rustpython_parser::{source_code::LinearLocator, Parse};
5+
pub use rustpython_compiler_core::{Mode, bytecode::CodeObject};
6+
pub use rustpython_parser::{Parse, source_code::LinearLocator};
77

88
// these modules are out of repository. re-exporting them here for convenience.
99
pub use rustpython_codegen as codegen;

0 commit comments

Comments
 (0)
0