Update __new__ method of Ellipsis
-use crate::function::PyFuncArgs;
+use crate::obj::objtype::{issubclass, PyClassRef};
use crate::pyobject::{PyContext, PyEllipsisRef, PyResult};
use crate::vm::VirtualMachine;
@@ -10,9 +10,15 @@ pub fn init(context: &PyContext) {
});
}
-fn ellipsis_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
- arg_check!(vm, args, required = [(_cls, None)]);
+fn ellipsis_new(cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
+ if issubclass(&cls, &vm.ctx.ellipsis_type) {
Ok(vm.ctx.ellipsis())
+ } else {
+ Err(vm.new_type_error(format!(
+ "ellipsis.__new__({ty}): {ty} is not a subtype of ellipsis",
+ ty = cls,
+ )))
+ }
}
fn ellipsis_repr(_self: PyEllipsisRef, _vm: &VirtualMachine) -> String {
