forked from Rust-related/RustPython
Update __new__ method of Ellipsis
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
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)]);
|
||||
Ok(vm.ctx.ellipsis())
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user