Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
098ba20
Add `unnecessary_wraps` clippy rule
ShaharNaveh May 12, 2026
0cf2f02
fix ssl/cert.rs
ShaharNaveh May 12, 2026
e076773
fix ssl.rs
ShaharNaveh May 12, 2026
873a654
select.rs
ShaharNaveh May 12, 2026
3b8c074
unicodedata
ShaharNaveh May 12, 2026
627e9cb
socket.rs
ShaharNaveh May 12, 2026
0de0b22
pyexpat
ShaharNaveh May 12, 2026
8a05e32
mmap
ShaharNaveh May 12, 2026
b139644
_opcode
ShaharNaveh May 12, 2026
81e3a75
locale
ShaharNaveh May 12, 2026
0a1c1bf
sha256 & sha512
ShaharNaveh May 12, 2026
518b7ec
contextvars
ShaharNaveh May 12, 2026
68edbf9
_asyncio
ShaharNaveh May 12, 2026
c8f47b0
warn.rs
ShaharNaveh May 12, 2026
2da829d
slot
ShaharNaveh May 12, 2026
d280bda
sys
ShaharNaveh May 12, 2026
bd57c08
_thread
ShaharNaveh May 12, 2026
87e5bf0
_signal
ShaharNaveh May 12, 2026
541d39b
_ctypes
ShaharNaveh May 12, 2026
88c64f1
os
ShaharNaveh May 12, 2026
66830b0
typevar
ShaharNaveh May 12, 2026
70f35ec
time
ShaharNaveh May 12, 2026
871438f
itertools
ShaharNaveh May 12, 2026
9863266
builtins
ShaharNaveh May 12, 2026
61b312c
_typing
ShaharNaveh May 12, 2026
7138481
_symtable
ShaharNaveh May 12, 2026
f845619
_operator
ShaharNaveh May 13, 2026
e1f5344
_io
ShaharNaveh May 13, 2026
c315d9a
_imp
ShaharNaveh May 13, 2026
f3edb2a
_functools
ShaharNaveh May 13, 2026
5551051
_collections
ShaharNaveh May 13, 2026
35affc4
_ast
ShaharNaveh May 13, 2026
4c57a30
frame.rs
ShaharNaveh May 13, 2026
788c0da
exceptions
ShaharNaveh May 13, 2026
a23b623
codecs
ShaharNaveh May 13, 2026
ea7a0ad
zip
ShaharNaveh May 13, 2026
5518f2a
slice
ShaharNaveh May 13, 2026
28eae26
set
ShaharNaveh May 13, 2026
fb0eb31
range
ShaharNaveh May 13, 2026
8f3d7a4
type
ShaharNaveh May 13, 2026
77d76bb
str
ShaharNaveh May 13, 2026
a6113f9
object
ShaharNaveh May 13, 2026
6868642
map
ShaharNaveh May 13, 2026
43296ec
int
ShaharNaveh May 13, 2026
afc8151
genericalias
ShaharNaveh May 13, 2026
1e3efd3
function
ShaharNaveh May 13, 2026
79744d2
frame
ShaharNaveh May 13, 2026
cb20bfd
asyncgenerator
ShaharNaveh May 13, 2026
bf9789a
format
ShaharNaveh May 13, 2026
af6b119
pypayload
ShaharNaveh May 13, 2026
dc3ec7e
pyclass
ShaharNaveh May 13, 2026
cdc45c3
util
ShaharNaveh May 13, 2026
8c253af
string_parser
ShaharNaveh May 13, 2026
eb40321
compile
ShaharNaveh May 13, 2026
06d7edf
Don't create `print_source_line` fn if no host_env
ShaharNaveh May 13, 2026
c8a425d
clippy when no host_env
ShaharNaveh May 13, 2026
49d5d75
sys
ShaharNaveh May 13, 2026
faadcdb
pwd
ShaharNaveh May 13, 2026
9c4dd84
os
ShaharNaveh May 13, 2026
9216bac
windows related
ShaharNaveh May 13, 2026
2b85da6
winreg
ShaharNaveh May 13, 2026
8fac28f
vm_class
ShaharNaveh May 13, 2026
2cd5d81
typo
ShaharNaveh May 13, 2026
0ac4d04
_sqlite3
ShaharNaveh May 13, 2026
35cacd9
grp
ShaharNaveh May 13, 2026
fc58a80
overlapped
ShaharNaveh May 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,4 @@ inconsistent_struct_constructor = "warn"
manual_is_variant_and = "warn"
map_unwrap_or = "warn"
must_use_candidate = "warn"
unnecessary_wraps = "warn"
142 changes: 67 additions & 75 deletions crates/codegen/src/compile.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions crates/codegen/src/string_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl StringParser {
self.source[self.cursor..].as_bytes().first().copied()
}

fn parse_unicode_literal(&mut self, literal_number: usize) -> Result<CodePoint, LexicalError> {
fn parse_unicode_literal(&mut self, literal_number: usize) -> CodePoint {
let mut p: u32 = 0u32;
for i in 1..=literal_number {
match self.next_char() {
Expand All @@ -79,7 +79,7 @@ impl StringParser {
None => unreachable!(),
}
}
Ok(CodePoint::from_u32(p).unwrap())
CodePoint::from_u32(p).unwrap()
}

fn parse_octet(&mut self, o: u8) -> char {
Expand Down Expand Up @@ -134,9 +134,9 @@ impl StringParser {
't' => '\t'.into(),
'v' => '\x0b'.into(),
o @ '0'..='7' => self.parse_octet(o as u8).into(),
'x' => self.parse_unicode_literal(2)?,
'u' if !self.flags.is_byte_string() => self.parse_unicode_literal(4)?,
'U' if !self.flags.is_byte_string() => self.parse_unicode_literal(8)?,
'x' => self.parse_unicode_literal(2),
'u' if !self.flags.is_byte_string() => self.parse_unicode_literal(4),
'U' if !self.flags.is_byte_string() => self.parse_unicode_literal(8),
'N' if !self.flags.is_byte_string() => self.parse_unicode_name()?.into(),
// Special cases where the escape sequence is not a single character
'\n' => return Ok(None),
Expand Down
44 changes: 33 additions & 11 deletions crates/common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,13 @@ impl FormatSpec {
},
};

self.format_sign_and_align(&AsciiStr::new(&magnitude_str), sign_str, FormatAlign::Right)
Ok(
self.format_sign_and_align(
&AsciiStr::new(&magnitude_str),
sign_str,
FormatAlign::Right,
),
)
}

/// Format a float with locale-aware 'n' format.
Expand Down Expand Up @@ -620,7 +626,13 @@ impl FormatSpec {
}
};

self.format_sign_and_align(&AsciiStr::new(&magnitude_str), sign_str, FormatAlign::Right)
Ok(
self.format_sign_and_align(
&AsciiStr::new(&magnitude_str),
sign_str,
FormatAlign::Right,
),
)
}

/// Format a complex number with locale-aware 'n' format.
Expand Down Expand Up @@ -672,7 +684,7 @@ impl FormatSpec {
// No parentheses for 'n' format (CPython: add_parens=0)
let magnitude_str = format!("{grouped_re}{grouped_im}");

self.format_sign_and_align(&AsciiStr::new(&magnitude_str), "", FormatAlign::Right)
Ok(self.format_sign_and_align(&AsciiStr::new(&magnitude_str), "", FormatAlign::Right))
}

pub fn format_bool(&self, input: bool) -> Result<String, FormatSpecError> {
Expand Down Expand Up @@ -789,7 +801,13 @@ impl FormatSpec {
}
};
let magnitude_str = self.add_magnitude_separators(raw_magnitude_str?, sign_str);
self.format_sign_and_align(&AsciiStr::new(&magnitude_str), sign_str, FormatAlign::Right)
Ok(
self.format_sign_and_align(
&AsciiStr::new(&magnitude_str),
sign_str,
FormatAlign::Right,
),
)
}

#[inline]
Expand Down Expand Up @@ -863,11 +881,11 @@ impl FormatSpec {
};
let sign_prefix = format!("{sign_str}{prefix}");
let magnitude_str = self.add_magnitude_separators(raw_magnitude_str, &sign_prefix);
self.format_sign_and_align(
Ok(self.format_sign_and_align(
&AsciiStr::new(&magnitude_str),
&sign_prefix,
FormatAlign::Right,
)
))
}

pub fn format_string<T>(&self, s: &T) -> Result<String, FormatSpecError>
Expand All @@ -883,7 +901,7 @@ impl FormatSpec {
Some(p) => s.deref().chars().take(p).collect(),
None => s.deref().to_owned(),
};
self.format_sign_and_align(&truncated, "", FormatAlign::Left)
Ok(self.format_sign_and_align(&truncated, "", FormatAlign::Left))
}
_ => {
let ch = char::from(self.format_type.as_ref().unwrap());
Expand All @@ -905,7 +923,11 @@ impl FormatSpec {
}
match &self.fill.unwrap_or_else(|| ' '.into()).to_char() {
Some('0') => Err(FormatSpecError::ZeroPadding),
_ => self.format_sign_and_align(&AsciiStr::new(&magnitude_str), "", FormatAlign::Right),
_ => Ok(self.format_sign_and_align(
&AsciiStr::new(&magnitude_str),
"",
FormatAlign::Right,
)),
}
}

Expand Down Expand Up @@ -1017,7 +1039,7 @@ impl FormatSpec {
magnitude_str: &T,
sign_str: &str,
default_align: FormatAlign,
) -> Result<String, FormatSpecError>
) -> String
where
T: CharLen + Deref<Target = str>,
{
Expand All @@ -1030,7 +1052,7 @@ impl FormatSpec {
});

let magnitude_str = magnitude_str.deref();
Ok(match align {
match align {
FormatAlign::Left => format!(
"{}{}{}",
sign_str,
Expand All @@ -1057,7 +1079,7 @@ impl FormatSpec {
Self::compute_fill_string(fill_char, right_fill_chars_needed);
format!("{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}")
}
})
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/derive-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn pyclass(attr: PunctuatedNestedMeta, item: Item) -> TokenStream {
#[must_use]
pub fn pyexception(attr: PunctuatedNestedMeta, item: Item) -> TokenStream {
if matches!(item, syn::Item::Impl(_)) {
result_to_tokens(pyclass::impl_pyexception_impl(attr, item))
pyclass::impl_pyexception_impl(attr, item)
} else {
result_to_tokens(pyclass::impl_pyexception(attr, item))
}
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn py_freeze(input: TokenStream, compiler: &dyn Compiler) -> TokenStream {

#[must_use]
pub fn pypayload(input: DeriveInput) -> TokenStream {
result_to_tokens(pypayload::impl_pypayload(input))
pypayload::impl_pypayload(input)
}

#[must_use]
Expand Down
26 changes: 13 additions & 13 deletions crates/derive-impl/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ pub(crate) fn impl_pyclass(attr: PunctuatedNestedMeta, item: Item) -> Result<Tok
// 1. no `clear`: HAS_CLEAR = HAS_TRAVERSE (default: same as traverse)
// 2. `clear` or `clear = true`: HAS_CLEAR = true, try_clear calls Traverse::clear
// 3. `clear = false`: HAS_CLEAR = false (rare: traverse without clear)
let has_traverse = class_meta.inner()._has_key("traverse")?;
let has_clear = if class_meta.inner()._has_key("clear")? {
let has_traverse = class_meta.inner()._has_key("traverse");
let has_clear = if class_meta.inner()._has_key("clear") {
// If clear attribute is present, use its value
class_meta.inner()._bool("clear")?
} else {
Expand Down Expand Up @@ -804,9 +804,9 @@ pub(crate) fn impl_pyexception(attr: PunctuatedNestedMeta, item: Item) -> Result
Ok(ret)
}

pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> Result<TokenStream> {
pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> TokenStream {
let Item::Impl(imp) = item else {
return Ok(item.into_token_stream());
return item.into_token_stream();
};

// Check if with(Constructor) is specified. If Constructor trait is used, don't generate slot_new
Expand Down Expand Up @@ -878,15 +878,15 @@ pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> R
quote!(, #(#extra_attrs),*)
};

Ok(quote! {
quote! {
#[pyclass(flags(BASETYPE, HAS_DICT), with(#(#with_items),*) #extra_attrs_tokens)]
impl #generics #self_ty {
#(#items)*
}

#slot_new
#slot_init
})
}
}

macro_rules! define_content_item {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ where
args.cfgs.to_vec(),
tokens,
2,
)?;
);

Ok(())
}
Expand Down Expand Up @@ -1235,7 +1235,7 @@ where

args.context
.attribute_items
.add_item(ident.clone(), vec![py_name], cfgs, tokens, 1)?;
.add_item(ident.clone(), vec![py_name], cfgs, tokens, 1);

Ok(())
}
Expand Down Expand Up @@ -1944,12 +1944,12 @@ fn extract_impl_attrs(attr: PunctuatedNestedMeta, item: &Ident) -> Result<Extrac
fn impl_item_new<Item>(
index: usize,
attr_name: AttrName,
) -> Result<Box<dyn ImplItem<Item, AttrName = AttrName>>>
) -> Box<dyn ImplItem<Item, AttrName = AttrName>>
where
Item: ItemLike + ToTokens + GetIdent,
{
use AttrName::*;
Ok(match attr_name {
match attr_name {
attr_name @ (Method | ClassMethod | StaticMethod) => Box::new(MethodItem {
inner: ContentItemInner { index, attr_name },
}),
Expand All @@ -1968,15 +1968,15 @@ where
Member => Box::new(MemberItem {
inner: ContentItemInner { index, attr_name },
}),
})
}
}

fn attrs_to_content_items<F, R>(
attrs: &[Attribute],
item_new: F,
) -> Result<(Vec<R>, Vec<Attribute>)>
where
F: Fn(usize, AttrName) -> Result<R>,
F: Fn(usize, AttrName) -> R,
{
let mut cfgs: Vec<Attribute> = Vec::new();
let mut result = Vec::new();
Expand Down Expand Up @@ -2018,7 +2018,7 @@ where
}
};

result.push(item_new(i, attr_name)?);
result.push(item_new(i, attr_name));
}
Ok((result, cfgs))
}
Expand Down
10 changes: 5 additions & 5 deletions crates/derive-impl/src/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl ModuleItem for ClassItem {
#set_attr
},
0,
)?;
);
Ok(())
}
}
Expand Down Expand Up @@ -910,7 +910,7 @@ impl ModuleItem for StructSequenceItem {
#set_attr
},
0,
)?;
);
Ok(())
}
}
Expand Down Expand Up @@ -995,9 +995,9 @@ impl ModuleItem for AttributeItem {
cfgs.clone(),
tokens,
1,
)?;
);
Ok(())
})?;
});
return Ok(());
}
other => {
Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl ModuleItem for AttributeItem {

args.context
.attribute_items
.add_item(ident, py_names, cfgs, tokens, 1)?;
.add_item(ident, py_names, cfgs, tokens, 1);

Ok(())
}
Expand Down
9 changes: 4 additions & 5 deletions crates/derive-impl/src/pypayload.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{DeriveInput, Result};
use syn::DeriveInput;

pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {
pub(crate) fn impl_pypayload(input: DeriveInput) -> TokenStream {
let ty = &input.ident;

let ret = quote! {
quote! {
impl ::rustpython_vm::PyPayload for #ty {
#[inline]
fn class(_ctx: &::rustpython_vm::vm::Context) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
<Self as ::rustpython_vm::class::StaticType>::static_type()
}
}
};
Ok(ret)
}
}
7 changes: 3 additions & 4 deletions crates/derive-impl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ impl ItemNursery {
cfgs: Vec<Attribute>,
tokens: TokenStream,
sort_order: usize,
) -> Result<()> {
) {
self.0.push(NurseryItem {
attr_name,
py_names,
cfgs,
tokens,
sort_order,
});
Ok(())
}

pub(crate) fn validate(self) -> Result<ValidatedItemNursery> {
Expand Down Expand Up @@ -216,8 +215,8 @@ impl ItemMetaInner {
Ok(value)
}

pub(crate) fn _has_key(&self, key: &str) -> Result<bool> {
Ok(matches!(self.meta_map.get(key), Some((_, _))))
pub(crate) fn _has_key(&self, key: &str) -> bool {
matches!(self.meta_map.get(key), Some((_, _)))
}

pub(crate) fn _bool(&self, key: &str) -> Result<bool> {
Expand Down
Loading
Loading