Skip to content

Commit af63e83

Browse files
committed
Makes args of type.__prepare__ optional, refs RustPython#2762
1 parent 43a43f7 commit af63e83

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

extra_tests/snippets/builtin_type.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,17 @@ def custom_func():
123123
pass
124124

125125
assert custom_func.__qualname__ == 'custom_func'
126+
127+
128+
# Regression to
129+
# https://github.com/RustPython/RustPython/issues/2762
130+
131+
assert type.__prepare__() == {}
132+
assert type.__prepare__('name') == {}
133+
assert type.__prepare__('name', object) == {}
134+
assert type.__prepare__('name', (bytes, str)) == {}
135+
assert type.__prepare__(a=1, b=2) == {}
136+
assert type.__prepare__('name', (object, int), kw=True) == {}
137+
138+
assert int.__prepare__() == {}
139+
assert int.__prepare__('name', (object, int), kw=True) == {}

vm/src/builtins/pytype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::staticmethod::PyStaticMethod;
1616
use super::tuple::PyTuple;
1717
use super::weakref::PyWeak;
1818
use crate::builtins::tuple::PyTupleTyped;
19-
use crate::function::{FuncArgs, KwArgs};
19+
use crate::function::{FuncArgs, KwArgs, OptionalArg};
2020
use crate::slots::{self, Callable, PyTpFlags, PyTypeSlots, SlotGetattro, SlotSetattro};
2121
use crate::utils::Either;
2222
use crate::vm::VirtualMachine;
@@ -345,8 +345,8 @@ impl PyType {
345345

346346
#[pymethod(magic)]
347347
fn prepare(
348-
_name: PyStrRef,
349-
_bases: PyObjectRef,
348+
_name: OptionalArg<PyStrRef>,
349+
_bases: OptionalArg<PyObjectRef>,
350350
_kwargs: KwArgs,
351351
vm: &VirtualMachine,
352352
) -> PyDictRef {

0 commit comments

Comments
 (0)