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

Skip to content

Commit 385ecb1

Browse files
committed
2024 edition formatting
1 parent 17d6efa commit 385ecb1

File tree

214 files changed

+643
-743
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

+643
-743
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 10000 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;

derive-impl/src/compile_bytecode.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ use crate::Diagnostic;
1717
use once_cell::sync::Lazy;
1818
use proc_macro2::{Span, TokenStream};
1919
use quote::quote;
20-
use rustpython_compiler_core::{bytecode::CodeObject, frozen, Mode};
20+
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
2121
use std::{
2222
collections::HashMap,
2323
env, fs,
2424
path::{Path, PathBuf},
2525
};
2626
use syn::{
27-
self,
27+
self, LitByteStr, LitStr, Macro,
2828
parse::{ParseStream, Parser, Result as ParseResult},
2929
spanned::Spanned,
30-
LitByteStr, LitStr, Macro,
3130
};
3231

3332
static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
@@ -118,11 +117,13 @@ impl CompilationSource {
118117
})?;
119118
self.compile_string(&source, mode, module_name, compiler, || rel_path.display())
120119
}
121-
CompilationSourceKind::SourceCode(code) => {
122-
self.compile_string(&textwrap::dedent(code), mode, module_name, compiler, || {
123-
"string literal"
124-
})
125-
}
120+
CompilationSourceKind::SourceCode(code) => self.compile_string(
121+
&textwrap::dedent(code),
122+
mode,
123+
module_name,
124+
compiler,
125+
|| "string literal",
126+
),
126127
CompilationSourceKind::Dir(_) => {
127128
unreachable!("Can't use compile_single with directory source")
128129
}

derive-impl/src/from_args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use proc_macro2::TokenStream;
2-
use quote::{quote, ToTokens};
2+
use quote::{ToTokens, quote};
33
use syn::ext::IdentExt;
44
use syn::meta::ParseNestedMeta;
5-
use syn::{parse_quote, Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token};
5+
use syn::{Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token, parse_quote};
66

77
/// The kind of the python parameter, this corresponds to the value of Parameter.kind
88
/// (https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind)

derive-impl/src/pyclass.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use super::Diagnostic;
22
use crate::util::{
3-
format_doc, pyclass_ident_and_attrs, pyexception_ident_and_attrs, text_signature,
4-
ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta, ItemMeta,
5-
ItemMetaInner, ItemNursery, SimpleItemMeta, ALL_ALLOWED_NAMES,
3+
ALL_ALLOWED_NAMES, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta,
4+
ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, format_doc, pyclass_ident_and_attrs,
5+
pyexception_ident_and_attrs, text_signature,
66
};
77
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
8-
use quote::{quote, quote_spanned, ToTokens};
8+
use quote::{ToTokens, quote, quote_spanned};
99
use std::collections::{HashMap, HashSet};
1010
use std::str::FromStr;
11-
use syn::{parse_quote, spanned::Spanned, Attribute, Ident, Item, Result};
11+
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
1212
use syn_ext::ext::*;
1313
use syn_ext::types::*;
1414

@@ -126,15 +126,15 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul
126126
return Err(syn::Error::new_spanned(
127127
segment,
128128
"Py{Ref}<T> is expected but Py{Ref}<?> is found",
129-
))
129+
));
130130
}
131131
}
132132
}
133133
_ => {
134134
return Err(syn::Error::new_spanned(
135135
segment,
136136
"Py{Ref}<T> is expected but Py{Ref}? is found",
137-
))
137+
));
138138
}
139139
}
140140
} else {
@@ -152,7 +152,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul
152152
return Err(syn::Error::new_spanned(
153153
imp.self_ty,
154154
"PyImpl can only be implemented for Py{Ref}<T> or T",
155-
))
155+
));
156156
}
157157
};
158158

@@ -1237,11 +1237,7 @@ impl MethodItemMeta {
12371237
name
12381238
} else {
12391239
let name = inner.item_name();
1240-
if magic {
1241-
format!("__{name}__")
1242-
} else {
1243-
name
1244-
}
1240+
if magic { format!("__{name}__") } else { name }
12451241
})
12461242
}
12471243
}
@@ -1308,11 +1304,7 @@ impl GetSetItemMeta {
13081304
GetSetItemKind::Set => extract_prefix_name("set_", "setter")?,
13091305
GetSetItemKind::Delete => extract_prefix_name("del_", "deleter")?,
13101306
};
1311-
if magic {
1312-
format!("__{name}__")
1313-
} else {
1314-
name
1315-
}
1307+
if magic { format!("__{name}__") } else { name }
13161308
};
13171309
Ok((py_name, kind))
13181310
}
@@ -1488,7 +1480,10 @@ fn extract_impl_attrs(attr: PunctuatedNestedMeta, item: &Ident) -> Result<Extrac
14881480
)
14891481
} else {
14901482
if path.is_ident("DefaultConstructor") {
1491-
bail_span!(meta, "Try `#[pyclass(with(Constructor, ...))]` instead of `#[pyclass(with(DefaultConstructor, ...))]`. DefaultConstructor implicitly implements Constructor.")
1483+
bail_span!(
1484+
meta,
1485+
"Try `#[pyclass(with(Constructor, ...))]` instead of `#[pyclass(with(DefaultConstructor, ...))]`. DefaultConstructor implicitly implements Constructor."
1486+
)
14921487
}
14931488
if path.is_ident("Constructor") || path.is_ident("Unconstructible") {
14941489
has_constructor = true;

derive-impl/src/pymodule.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::error::Diagnostic;
22
use crate::util::{
3-
format_doc, iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta,
4-
AttributeExt, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery,
5-
ModuleItemMeta, SimpleItemMeta, ALL_ALLOWED_NAMES,
3+
ALL_ALLOWED_NAMES, AttrItemMeta, AttributeExt, ClassItemMeta, ContentItem, ContentItemInner,
4+
ErrorVec, ItemMeta, ItemNursery, ModuleItemMeta, SimpleItemMeta, format_doc, iter_use_idents,
5+
pyclass_ident_and_attrs, text_signature,
66
};
77
use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
8-
use quote::{quote, quote_spanned, ToTokens};
8+
use quote::{ToTokens, quote, quote_spanned};
99
use std::{collections::HashSet, str::FromStr};
10-
use syn::{parse_quote, spanned::Spanned, Attribute, Ident, Item, Result};
10+
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
1111
use syn_ext::ext::*;
1212
use syn_ext::types::PunctuatedNestedMeta;
1313

@@ -688,7 +688,7 @@ impl ModuleItem for AttributeItem {
688688
other => {
689689
return Err(
690690
self.new_syn_error(other.span(), "can only be on a function, const and use")
691-
)
691+
);
692692
}
693693
};
694694

0 commit comments

Comments
 (0)
0