Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 19 additions & 25 deletions crates/stdlib/src/_sqlite3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3537,36 +3537,30 @@ mod _sqlite3 {
// Skip whitespace.
pos += 1;
}
b'-' => {
// Skip line comments.
if sql.get(pos + 1) == Some(&b'-') {
pos += 2;
while let Some(&ch) = sql.get(pos) {
if ch == b'\n' {
break;
}
pos += 1;

// Skip line comments.
b'-' if sql.get(pos + 1) == Some(&b'-') => {
pos += 2;
while let Some(&ch) = sql.get(pos) {
if ch == b'\n' {
break;
}
let _ = sql.get(pos)?;
} else {
return Some(&sql[pos..]);
pos += 1;
}
let _ = sql.get(pos)?;
}
b'/' => {
// Skip C style comments.
if sql.get(pos + 1) == Some(&b'*') {
pos += 2;
while let Some(&ch) = sql.get(pos) {
if ch == b'*' && sql.get(pos + 1) == Some(&b'/') {
break;
}
pos += 1;

// Skip C style comments.
b'/' if sql.get(pos + 1) == Some(&b'*') => {
pos += 2;
while let Some(&ch) = sql.get(pos) {
if ch == b'*' && sql.get(pos + 1) == Some(&b'/') {
break;
}
let _ = sql.get(pos)?;
pos += 2;
} else {
return Some(&sql[pos..]);
pos += 1;
}
let _ = sql.get(pos)?;
pos += 2;
}
_ => {
return Some(&sql[pos..]);
Expand Down
4 changes: 1 addition & 3 deletions crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2103,9 +2103,8 @@ impl Constructor for PyType {
.map_err(|e| vm.new_type_error(e))?;

if let Some(ref slots) = heaptype_slots {
let mut offset = base_member_count;
let class_name = typ.name().to_string();
for member in slots.as_slice() {
for (offset, member) in (base_member_count..).zip(slots.as_slice().iter()) {
// Apply name mangling for private attributes (__x -> _ClassName__x)
let member_str = member
.to_str()
Expand All @@ -2131,7 +2130,6 @@ impl Constructor for PyType {
// __slots__ attributes always get a member descriptor
// (this overrides any inherited attribute from MRO)
typ.set_attr(attr_name, member_descriptor.into());
offset += 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ fn dedup_and_flatten_args(args: &Py<PyTuple>, vm: &VirtualMachine) -> PyResult<U

// Create hashable_args frozenset if there are hashable elements
let hashable_args = if !hashable_list.is_empty() {
Some(PyFrozenSet::from_iter(vm, hashable_list.into_iter())?.into_ref(&vm.ctx))
Some(PyFrozenSet::from_iter(vm, hashable_list)?.into_ref(&vm.ctx))
} else {
None
};
Expand Down Expand Up @@ -517,7 +517,7 @@ impl Hashable for PyUnion {
Err(e) => return Err(e),
}
}
let set = PyFrozenSet::from_iter(vm, args_to_hash.into_iter())?;
let set = PyFrozenSet::from_iter(vm, args_to_hash)?;
PyFrozenSet::hash(&set.into_ref(&vm.ctx), vm)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl<'a> DecodeErrorHandler<PyDecodeContext<'a>> for SurrogatePass {
.ok_or_else(|| ctx.error_decoding(byte_range.clone(), reason))?;

let s = ctx.full_data();
debug_assert!(byte_range.start <= 0.max(s.len() - 1));
debug_assert!(byte_range.start <= s.len().saturating_sub(1));
debug_assert!(byte_range.end >= 1.min(s.len()));
debug_assert!(byte_range.end <= s.len());

Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/stdlib/_abc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod _abc {
}

// Set __abstractmethods__
let abstracts_set = PyFrozenSet::from_iter(vm, abstracts.into_iter())?;
let abstracts_set = PyFrozenSet::from_iter(vm, abstracts)?;
cls.set_attr("__abstractmethods__", abstracts_set.into_pyobject(vm), vm)?;

Ok(())
Expand Down Expand Up @@ -302,7 +302,7 @@ mod _abc {
drop(registry_opt);

// Make a local copy to protect against concurrent modifications
let registry_copy = PyFrozenSet::from_iter(vm, registry.elements().into_iter())?;
let registry_copy = PyFrozenSet::from_iter(vm, registry.elements())?;

for weak_ref_obj in registry_copy.elements() {
if let Ok(weak_ref) = weak_ref_obj.downcast::<PyWeak>()
Expand Down
17 changes: 9 additions & 8 deletions crates/vm/src/stdlib/_ctypes/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,17 @@ impl PyCSimpleType {
// 4. Try to convert value based on type code
match type_code.as_deref() {
// Integer types: accept integers
Some(tc @ ("b" | "B" | "h" | "H" | "i" | "I" | "l" | "L" | "q" | "Q")) => {
if value.try_int(vm).is_ok() {
return create_simple_with_value(tc, &value);
}
Some(tc @ ("b" | "B" | "h" | "H" | "i" | "I" | "l" | "L" | "q" | "Q"))
if value.try_int(vm).is_ok() =>
{
return create_simple_with_value(tc, &value);
}

// Float types: accept numbers
Some(tc @ ("f" | "d" | "g")) => {
if value.try_float(vm).is_ok() || value.try_int(vm).is_ok() {
return create_simple_with_value(tc, &value);
}
Some(tc @ ("f" | "d" | "g"))
if (value.try_float(vm).is_ok() || value.try_int(vm).is_ok()) =>
{
return create_simple_with_value(tc, &value);
}
// c_char: 1 byte character
Some("c") => {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/_winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ mod _winapi {
// Deduplicate case-insensitive keys, keeping the last value
use std::collections::HashMap;
let mut last_entry: HashMap<String, widestring::WideString> = HashMap::new();
for (k, v) in keys.into_iter().zip(values.into_iter()) {
for (k, v) in keys.into_iter().zip(values) {
let k = PyStrRef::try_from_object(vm, k)?;
let k = k.expect_str();
let v = PyStrRef::try_from_object(vm, v)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,8 @@ mod platform {
let zone = widestring::decode_utf16_lossy(name.iter().copied())
.take_while(|&c| c != '\0')
.collect::<String>();

#[allow(clippy::unnecessary_cast, reason = "info.Bias is not always i32")]
let gmtoff = -((info.Bias + bias) as i32) * 60;

Ok(struct_time_from_tm(vm, tm, &zone, gmtoff))
Expand Down
10 changes: 4 additions & 6 deletions crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,12 +1394,10 @@ impl PyType {
SlotAccessor::SqLength => {
update_sub_slot!(as_sequence, length, sequence_len_wrapper, SeqLength)
}
SlotAccessor::SqConcat | SlotAccessor::SqInplaceConcat => {
// Sequence concat uses sq_concat slot - no generic wrapper needed
// (handled by number protocol fallback)
if !ADD {
accessor.inherit_from_mro(self);
}
// Sequence concat uses sq_concat slot - no generic wrapper needed
// (handled by number protocol fallback)
SlotAccessor::SqConcat | SlotAccessor::SqInplaceConcat if !ADD => {
accessor.inherit_from_mro(self);
}
SlotAccessor::SqRepeat => {
update_sub_slot!(as_sequence, repeat, sequence_repeat_wrapper, SeqRepeat)
Expand Down
Loading