Skip to content

Commit 78c23c5

Browse files
committed
apply review
1 parent 0d791f9 commit 78c23c5

5 files changed

Lines changed: 19 additions & 21 deletions

File tree

crates/derive-impl/src/pyclass.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -735,12 +735,7 @@ pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> R
735735

736736
let with_contains = |with_items: &[Ident], s: &str| {
737737
// Check if Constructor is in the list
738-
for ident in with_items {
739-
if ident.to_string().as_str() == s {
740-
return true;
741-
}
742-
}
743-
false
738+
with_items.iter().any(|ident| ident == s)
744739
};
745740

746741
let syn::ItemImpl {
@@ -768,8 +763,8 @@ pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> R
768763
fn py_new(
769764
_cls: &::rustpython_vm::Py<::rustpython_vm::builtins::PyType>,
770765
_args: Self::Args,
771-
_vm: &VirtualMachine
772-
) -> PyResult<Self> {
766+
_vm: &::rustpython_vm::VirtualMachine
767+
) -> ::rustpython_vm::PyResult<Self> {
773768
unreachable!("slot_new is defined")
774769
}
775770
}
@@ -792,15 +787,15 @@ pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> R
792787
zelf: ::rustpython_vm::PyObjectRef,
793788
args: ::rustpython_vm::function::FuncArgs,
794789
vm: &::rustpython_vm::VirtualMachine,
795-
) -> PyResult<()> {
790+
) -> ::rustpython_vm::PyResult<()> {
796791
<Self as ::rustpython_vm::class::PyClassDef>::Base::slot_init(zelf, args, vm)
797792
}
798793

799794
fn init(
800795
_zelf: ::rustpython_vm::PyRef<Self>,
801796
_args: Self::Args,
802-
_vm: &VirtualMachine
803-
) -> PyResult<()> {
797+
_vm: &::rustpython_vm::VirtualMachine
798+
) -> ::rustpython_vm::PyResult<()> {
804799
unreachable!("slot_init is defined")
805800
}
806801
}

crates/stdlib/src/sqlite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,9 @@ mod _sqlite {
19321932
}
19331933

19341934
impl Initializer for Cursor {
1935-
type Args = FuncArgs;
1935+
type Args = PyRef<Connection>;
19361936

1937-
fn init(zelf: PyRef<Self>, _connection: FuncArgs, _vm: &VirtualMachine) -> PyResult<()> {
1937+
fn init(zelf: PyRef<Self>, _connection: Self::Args, _vm: &VirtualMachine) -> PyResult<()> {
19381938
let mut guard = zelf.inner.lock();
19391939
if guard.is_some() {
19401940
// Already initialized (e.g., from a call to super().__init__)

crates/vm/src/exception_group.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,21 @@ pub(super) mod types {
242242
}
243243

244244
impl Constructor for PyBaseExceptionGroup {
245-
type Args = FuncArgs;
245+
type Args = crate::function::PosArgs;
246246

247247
fn slot_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
248+
let args: Self::Args = args.bind(vm)?;
249+
let args = args.into_vec();
248250
// Validate exactly 2 positional arguments
249-
if args.args.len() != 2 {
251+
if args.len() != 2 {
250252
return Err(vm.new_type_error(format!(
251253
"BaseExceptionGroup.__new__() takes exactly 2 positional arguments ({} given)",
252-
args.args.len()
254+
args.len()
253255
)));
254256
}
255257

256258
// Validate message is str
257-
let message = args.args[0].clone();
259+
let message = args[0].clone();
258260
if !message.fast_isinstance(vm.ctx.types.str_type) {
259261
return Err(vm.new_type_error(format!(
260262
"argument 1 must be str, not {}",
@@ -263,7 +265,7 @@ pub(super) mod types {
263265
}
264266

265267
// Validate exceptions is a sequence (not set or None)
266-
let exceptions_arg = &args.args[1];
268+
let exceptions_arg = &args[1];
267269

268270
// Check for set/frozenset (not a sequence - unordered)
269271
if exceptions_arg.fast_isinstance(vm.ctx.types.set_type)
@@ -343,7 +345,7 @@ pub(super) mod types {
343345
.map(Into::into)
344346
}
345347

346-
fn py_new(_cls: &Py<PyType>, _args: FuncArgs, _vm: &VirtualMachine) -> PyResult<Self> {
348+
fn py_new(_cls: &Py<PyType>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<Self> {
347349
unimplemented!("use slot_new")
348350
}
349351
}

crates/vm/src/exceptions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,9 +2130,9 @@ pub(super) mod types {
21302130
impl Initializer for PyIncompleteInputError {
21312131
type Args = FuncArgs;
21322132

2133-
fn slot_init(zelf: PyObjectRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
2133+
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
21342134
zelf.set_attr("name", vm.ctx.new_str("SyntaxError"), vm)?;
2135-
Ok(())
2135+
PySyntaxError::slot_init(zelf, args, vm)
21362136
}
21372137

21382138
fn init(_zelf: PyRef<Self>, _args: Self::Args, _vm: &VirtualMachine) -> PyResult<()> {

crates/vm/src/stdlib/ast/python.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub(crate) mod _ast {
3939
let zelf = vm.ctx.new_base_object(cls, dict);
4040

4141
// Initialize the instance with the provided arguments
42+
// FIXME: This is probably incorrect. Please check if init should be called outside of __new__
4243
Self::slot_init(zelf.clone(), args, vm)?;
4344

4445
Ok(zelf)

0 commit comments

Comments
 (0)