Merge pull request #1749 from youknowone/_vm

Remove `_vm` parameter when it is not required
This commit is contained in:
Jeong YunWon
2020-02-06 20:33:43 +09:00
committed by GitHub
58 changed files with 424 additions and 517 deletions

View File

@@ -87,7 +87,7 @@ pub fn to_ascii(value: &str) -> String {
ascii
}
fn builtin_bin(x: PyIntRef, _vm: &VirtualMachine) -> String {
fn builtin_bin(x: PyIntRef) -> String {
let x = x.as_bigint();
if x.is_negative() {
format!("-0b{:b}", x.abs())
@@ -343,7 +343,7 @@ fn builtin_hex(number: PyIntRef, vm: &VirtualMachine) -> PyResult {
Ok(vm.new_str(s))
}
fn builtin_id(obj: PyObjectRef, _vm: &VirtualMachine) -> usize {
fn builtin_id(obj: PyObjectRef) -> usize {
obj.get_id()
}
@@ -391,7 +391,7 @@ fn builtin_len(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
fn builtin_locals(vm: &VirtualMachine) -> PyDictRef {
let locals = vm.get_locals();
locals.copy(vm).into_ref(vm)
locals.copy().into_ref(vm)
}
fn builtin_max(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {

View File

@@ -67,8 +67,8 @@ impl PyBaseException {
Ok(())
}
#[pyproperty(name = "args")]
fn get_args(&self, _vm: &VirtualMachine) -> PyTupleRef {
#[pyproperty]
pub fn args(&self) -> PyTupleRef {
self.args.borrow().clone()
}
@@ -80,7 +80,7 @@ impl PyBaseException {
}
#[pyproperty(name = "__traceback__")]
fn get_traceback(&self) -> Option<PyTracebackRef> {
pub fn traceback(&self) -> Option<PyTracebackRef> {
self.traceback.borrow().clone()
}
@@ -90,51 +90,37 @@ impl PyBaseException {
}
#[pyproperty(name = "__cause__")]
fn get_cause(&self, _vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
pub fn cause(&self) -> Option<PyBaseExceptionRef> {
self.cause.borrow().clone()
}
#[pyproperty(name = "__cause__", setter)]
fn setter_cause(
&self,
cause: Option<PyBaseExceptionRef>,
_vm: &VirtualMachine,
) -> PyResult<()> {
pub fn set_cause(&self, cause: Option<PyBaseExceptionRef>) {
self.cause.replace(cause);
Ok(())
}
#[pyproperty(name = "__context__")]
fn get_context(&self, _vm: &VirtualMachine) -> Option<PyBaseExceptionRef> {
pub fn context(&self) -> Option<PyBaseExceptionRef> {
self.context.borrow().clone()
}
#[pyproperty(name = "__context__", setter)]
fn setter_context(
&self,
context: Option<PyBaseExceptionRef>,
_vm: &VirtualMachine,
) -> PyResult<()> {
pub fn set_context(&self, context: Option<PyBaseExceptionRef>) {
self.context.replace(context);
Ok(())
}
#[pyproperty(name = "__suppress_context__")]
fn get_suppress_context(&self, _vm: &VirtualMachine) -> bool {
fn get_suppress_context(&self) -> bool {
self.suppress_context.get()
}
#[pyproperty(name = "__suppress_context__", setter)]
fn set_suppress_context(&self, suppress_context: bool, _vm: &VirtualMachine) {
fn set_suppress_context(&self, suppress_context: bool) {
self.suppress_context.set(suppress_context);
}
#[pymethod]
fn with_traceback(
zelf: PyRef<Self>,
tb: Option<PyTracebackRef>,
_vm: &VirtualMachine,
) -> PyResult {
fn with_traceback(zelf: PyRef<Self>, tb: Option<PyTracebackRef>) -> PyResult {
zelf.traceback.replace(tb);
Ok(zelf.as_object().clone())
}
@@ -158,28 +144,6 @@ impl PyBaseException {
Err(i) => format!("{}({})", cls.name, i.format(", ")),
}
}
pub fn args(&self) -> PyTupleRef {
self.args.borrow().clone()
}
pub fn traceback(&self) -> Option<PyTracebackRef> {
self.traceback.borrow().clone()
}
pub fn cause(&self) -> Option<PyBaseExceptionRef> {
self.cause.borrow().clone()
}
pub fn set_cause(&self, cause: Option<PyBaseExceptionRef>) {
self.cause.replace(cause);
}
pub fn context(&self) -> Option<PyBaseExceptionRef> {
self.context.borrow().clone()
}
pub fn set_context(&self, context: Option<PyBaseExceptionRef>) {
self.context.replace(context);
}
}
/// Print exception chain

View File

@@ -337,7 +337,7 @@ impl Frame {
bytecode::Instruction::ListAppend { i } => {
let list_obj = self.nth_value(*i);
let item = self.pop_value();
objlist::PyListRef::try_from_object(vm, list_obj)?.append(item, vm);
objlist::PyListRef::try_from_object(vm, list_obj)?.append(item);
Ok(None)
}
bytecode::Instruction::SetAdd { i } => {

View File

@@ -118,7 +118,7 @@ pub fn get_py_int(obj: &PyObjectRef) -> &PyInt {
&obj.payload::<PyInt>().unwrap()
}
fn bool_repr(obj: bool, _vm: &VirtualMachine) -> String {
fn bool_repr(obj: bool) -> String {
if obj {
"True".to_owned()
} else {

View File

@@ -99,17 +99,17 @@ impl PyByteArray {
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> PyResult<String> {
fn repr(&self) -> PyResult<String> {
Ok(format!("bytearray(b'{}')", self.inner.borrow().repr()?))
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.inner.borrow().len()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
size_of::<Self>() + self.inner.borrow().len() * size_of::<u8>()
}
@@ -144,7 +144,7 @@ impl PyByteArray {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyByteArrayIterator {
fn iter(zelf: PyRef<Self>) -> PyByteArrayIterator {
PyByteArrayIterator {
position: Cell::new(0),
bytearray: zelf,
@@ -190,67 +190,67 @@ impl PyByteArray {
}
#[pymethod(name = "isalnum")]
fn isalnum(&self, _vm: &VirtualMachine) -> bool {
fn isalnum(&self) -> bool {
self.inner.borrow().isalnum()
}
#[pymethod(name = "isalpha")]
fn isalpha(&self, _vm: &VirtualMachine) -> bool {
fn isalpha(&self) -> bool {
self.inner.borrow().isalpha()
}
#[pymethod(name = "isascii")]
fn isascii(&self, _vm: &VirtualMachine) -> bool {
fn isascii(&self) -> bool {
self.inner.borrow().isascii()
}
#[pymethod(name = "isdigit")]
fn isdigit(&self, _vm: &VirtualMachine) -> bool {
fn isdigit(&self) -> bool {
self.inner.borrow().isdigit()
}
#[pymethod(name = "islower")]
fn islower(&self, _vm: &VirtualMachine) -> bool {
fn islower(&self) -> bool {
self.inner.borrow().islower()
}
#[pymethod(name = "isspace")]
fn isspace(&self, _vm: &VirtualMachine) -> bool {
fn isspace(&self) -> bool {
self.inner.borrow().isspace()
}
#[pymethod(name = "isupper")]
fn isupper(&self, _vm: &VirtualMachine) -> bool {
fn isupper(&self) -> bool {
self.inner.borrow().isupper()
}
#[pymethod(name = "istitle")]
fn istitle(&self, _vm: &VirtualMachine) -> bool {
fn istitle(&self) -> bool {
self.inner.borrow().istitle()
}
#[pymethod(name = "lower")]
fn lower(&self, _vm: &VirtualMachine) -> PyByteArray {
fn lower(&self) -> PyByteArray {
self.inner.borrow().lower().into()
}
#[pymethod(name = "upper")]
fn upper(&self, _vm: &VirtualMachine) -> PyByteArray {
fn upper(&self) -> PyByteArray {
self.inner.borrow().upper().into()
}
#[pymethod(name = "capitalize")]
fn capitalize(&self, _vm: &VirtualMachine) -> PyByteArray {
fn capitalize(&self) -> PyByteArray {
self.inner.borrow().capitalize().into()
}
#[pymethod(name = "swapcase")]
fn swapcase(&self, _vm: &VirtualMachine) -> PyByteArray {
fn swapcase(&self) -> PyByteArray {
self.inner.borrow().swapcase().into()
}
#[pymethod(name = "hex")]
fn hex(&self, _vm: &VirtualMachine) -> String {
fn hex(&self) -> String {
self.inner.borrow().hex()
}
@@ -375,11 +375,7 @@ impl PyByteArray {
}
#[pymethod(name = "strip")]
fn strip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn strip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
@@ -388,11 +384,7 @@ impl PyByteArray {
}
#[pymethod(name = "lstrip")]
fn lstrip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn lstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
@@ -401,11 +393,7 @@ impl PyByteArray {
}
#[pymethod(name = "rstrip")]
fn rstrip(
&self,
chars: OptionalArg<PyByteInner>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
fn rstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyByteArray> {
Ok(self
.inner
.borrow()
@@ -460,7 +448,7 @@ impl PyByteArray {
}
#[pymethod(name = "expandtabs")]
fn expandtabs(&self, options: ByteInnerExpandtabsOptions, _vm: &VirtualMachine) -> PyByteArray {
fn expandtabs(&self, options: ByteInnerExpandtabsOptions) -> PyByteArray {
self.inner.borrow().expandtabs(options).into()
}
@@ -477,7 +465,7 @@ impl PyByteArray {
}
#[pymethod(name = "zfill")]
fn zfill(&self, width: PyIntRef, _vm: &VirtualMachine) -> PyByteArray {
fn zfill(&self, width: PyIntRef) -> PyByteArray {
self.inner.borrow().zfill(width).into()
}
@@ -487,18 +475,17 @@ impl PyByteArray {
old: PyByteInner,
new: PyByteInner,
count: OptionalArg<PyIntRef>,
_vm: &VirtualMachine,
) -> PyResult<PyByteArray> {
Ok(self.inner.borrow().replace(old, new, count)?.into())
}
#[pymethod(name = "clear")]
fn clear(&self, _vm: &VirtualMachine) {
fn clear(&self) {
self.inner.borrow_mut().elements.clear();
}
#[pymethod(name = "copy")]
fn copy(&self, _vm: &VirtualMachine) -> PyByteArray {
fn copy(&self) -> PyByteArray {
self.inner.borrow().elements.clone().into()
}
@@ -560,22 +547,22 @@ impl PyByteArray {
}
#[pymethod(name = "title")]
fn title(&self, _vm: &VirtualMachine) -> PyByteArray {
fn title(&self) -> PyByteArray {
self.inner.borrow().title().into()
}
#[pymethod(name = "__mul__")]
fn repeat(&self, n: isize, _vm: &VirtualMachine) -> PyByteArray {
fn repeat(&self, n: isize) -> PyByteArray {
self.inner.borrow().repeat(n).into()
}
#[pymethod(name = "__rmul__")]
fn rmul(&self, n: isize, vm: &VirtualMachine) -> PyByteArray {
self.repeat(n, vm)
fn rmul(&self, n: isize) -> PyByteArray {
self.repeat(n)
}
#[pymethod(name = "__imul__")]
fn irepeat(&self, n: isize, _vm: &VirtualMachine) {
fn irepeat(&self, n: isize) {
self.inner.borrow_mut().irepeat(n)
}
@@ -603,7 +590,7 @@ impl PyByteArray {
}
#[pymethod(name = "reverse")]
fn reverse(&self, _vm: &VirtualMachine) -> PyResult<()> {
fn reverse(&self) -> PyResult<()> {
self.inner.borrow_mut().elements.reverse();
Ok(())
}
@@ -640,7 +627,7 @@ impl PyByteArrayIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -109,7 +109,7 @@ impl PyBytes {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.inner.len()
}
@@ -135,12 +135,12 @@ impl PyBytes {
}
#[pymethod(name = "__hash__")]
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
fn hash(&self) -> pyhash::PyHash {
self.inner.hash()
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyBytesIterator {
fn iter(zelf: PyRef<Self>) -> PyBytesIterator {
PyBytesIterator {
position: Cell::new(0),
bytes: zelf,
@@ -148,7 +148,7 @@ impl PyBytes {
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> PyResult<usize> {
fn sizeof(&self) -> PyResult<usize> {
Ok(size_of::<Self>() + self.inner.elements.len() * size_of::<u8>())
}
@@ -176,67 +176,67 @@ impl PyBytes {
}
#[pymethod(name = "isalnum")]
fn isalnum(&self, _vm: &VirtualMachine) -> bool {
fn isalnum(&self) -> bool {
self.inner.isalnum()
}
#[pymethod(name = "isalpha")]
fn isalpha(&self, _vm: &VirtualMachine) -> bool {
fn isalpha(&self) -> bool {
self.inner.isalpha()
}
#[pymethod(name = "isascii")]
fn isascii(&self, _vm: &VirtualMachine) -> bool {
fn isascii(&self) -> bool {
self.inner.isascii()
}
#[pymethod(name = "isdigit")]
fn isdigit(&self, _vm: &VirtualMachine) -> bool {
fn isdigit(&self) -> bool {
self.inner.isdigit()
}
#[pymethod(name = "islower")]
fn islower(&self, _vm: &VirtualMachine) -> bool {
fn islower(&self) -> bool {
self.inner.islower()
}
#[pymethod(name = "isspace")]
fn isspace(&self, _vm: &VirtualMachine) -> bool {
fn isspace(&self) -> bool {
self.inner.isspace()
}
#[pymethod(name = "isupper")]
fn isupper(&self, _vm: &VirtualMachine) -> bool {
fn isupper(&self) -> bool {
self.inner.isupper()
}
#[pymethod(name = "istitle")]
fn istitle(&self, _vm: &VirtualMachine) -> bool {
fn istitle(&self) -> bool {
self.inner.istitle()
}
#[pymethod(name = "lower")]
fn lower(&self, _vm: &VirtualMachine) -> PyBytes {
fn lower(&self) -> PyBytes {
self.inner.lower().into()
}
#[pymethod(name = "upper")]
fn upper(&self, _vm: &VirtualMachine) -> PyBytes {
fn upper(&self) -> PyBytes {
self.inner.upper().into()
}
#[pymethod(name = "capitalize")]
fn capitalize(&self, _vm: &VirtualMachine) -> PyBytes {
fn capitalize(&self) -> PyBytes {
self.inner.capitalize().into()
}
#[pymethod(name = "swapcase")]
fn swapcase(&self, _vm: &VirtualMachine) -> PyBytes {
fn swapcase(&self) -> PyBytes {
self.inner.swapcase().into()
}
#[pymethod(name = "hex")]
fn hex(&self, _vm: &VirtualMachine) -> String {
fn hex(&self) -> String {
self.inner.hex()
}
@@ -330,17 +330,17 @@ impl PyBytes {
}
#[pymethod(name = "strip")]
fn strip(&self, chars: OptionalArg<PyByteInner>, _vm: &VirtualMachine) -> PyResult<PyBytes> {
fn strip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyBytes> {
Ok(self.inner.strip(chars, ByteInnerPosition::All)?.into())
}
#[pymethod(name = "lstrip")]
fn lstrip(&self, chars: OptionalArg<PyByteInner>, _vm: &VirtualMachine) -> PyResult<PyBytes> {
fn lstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyBytes> {
Ok(self.inner.strip(chars, ByteInnerPosition::Left)?.into())
}
#[pymethod(name = "rstrip")]
fn rstrip(&self, chars: OptionalArg<PyByteInner>, _vm: &VirtualMachine) -> PyResult<PyBytes> {
fn rstrip(&self, chars: OptionalArg<PyByteInner>) -> PyResult<PyBytes> {
Ok(self.inner.strip(chars, ByteInnerPosition::Right)?.into())
}
@@ -386,7 +386,7 @@ impl PyBytes {
}
#[pymethod(name = "expandtabs")]
fn expandtabs(&self, options: ByteInnerExpandtabsOptions, _vm: &VirtualMachine) -> PyBytes {
fn expandtabs(&self, options: ByteInnerExpandtabsOptions) -> PyBytes {
self.inner.expandtabs(options).into()
}
@@ -402,7 +402,7 @@ impl PyBytes {
}
#[pymethod(name = "zfill")]
fn zfill(&self, width: PyIntRef, _vm: &VirtualMachine) -> PyBytes {
fn zfill(&self, width: PyIntRef) -> PyBytes {
self.inner.zfill(width).into()
}
@@ -412,24 +412,23 @@ impl PyBytes {
old: PyByteInner,
new: PyByteInner,
count: OptionalArg<PyIntRef>,
_vm: &VirtualMachine,
) -> PyResult<PyBytes> {
Ok(self.inner.replace(old, new, count)?.into())
}
#[pymethod(name = "title")]
fn title(&self, _vm: &VirtualMachine) -> PyBytes {
fn title(&self) -> PyBytes {
self.inner.title().into()
}
#[pymethod(name = "__mul__")]
fn repeat(&self, n: isize, _vm: &VirtualMachine) -> PyBytes {
fn repeat(&self, n: isize) -> PyBytes {
self.inner.repeat(n).into()
}
#[pymethod(name = "__rmul__")]
fn rmul(&self, n: isize, vm: &VirtualMachine) -> PyBytes {
self.repeat(n, vm)
fn rmul(&self, n: isize) -> PyBytes {
self.repeat(n)
}
fn do_cformat(
@@ -512,7 +511,7 @@ impl PyBytesIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -75,7 +75,7 @@ impl PyClassMethod {
}
#[pyproperty(name = "__func__")]
fn func(&self, _vm: &VirtualMachine) -> PyObjectRef {
fn func(&self) -> PyObjectRef {
self.callable.clone()
}
}

View File

@@ -47,7 +47,7 @@ impl PyCodeRef {
Err(vm.new_type_error("Cannot directly create code object".to_owned()))
}
fn repr(self, _vm: &VirtualMachine) -> String {
fn repr(self) -> String {
let code = &self.code;
format!(
"<code object {} at 0x{:x} file {:?}, line {}>",
@@ -58,19 +58,19 @@ impl PyCodeRef {
)
}
fn co_argcount(self, _vm: &VirtualMachine) -> usize {
fn co_argcount(self) -> usize {
self.code.arg_names.len()
}
fn co_filename(self, _vm: &VirtualMachine) -> String {
fn co_filename(self) -> String {
self.code.source_path.clone()
}
fn co_firstlineno(self, _vm: &VirtualMachine) -> usize {
fn co_firstlineno(self) -> usize {
self.code.first_line_number
}
fn co_kwonlyargcount(self, _vm: &VirtualMachine) -> usize {
fn co_kwonlyargcount(self) -> usize {
self.code.kwonlyarg_names.len()
}
@@ -83,11 +83,11 @@ impl PyCodeRef {
vm.ctx.new_tuple(consts)
}
fn co_name(self, _vm: &VirtualMachine) -> String {
fn co_name(self) -> String {
self.code.obj_name.clone()
}
fn co_flags(self, _vm: &VirtualMachine) -> u8 {
fn co_flags(self) -> u8 {
self.code.flags.bits()
}
}

View File

@@ -57,17 +57,17 @@ fn try_complex(value: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<Comp
#[pyimpl(flags(BASETYPE))]
impl PyComplex {
#[pyproperty(name = "real")]
fn real(&self, _vm: &VirtualMachine) -> f64 {
fn real(&self) -> f64 {
self.value.re
}
#[pyproperty(name = "imag")]
fn imag(&self, _vm: &VirtualMachine) -> f64 {
fn imag(&self) -> f64 {
self.value.im
}
#[pymethod(name = "__abs__")]
fn abs(&self, _vm: &VirtualMachine) -> f64 {
fn abs(&self) -> f64 {
let Complex64 { im, re } = self.value;
re.hypot(im)
}
@@ -104,7 +104,7 @@ impl PyComplex {
}
#[pymethod(name = "conjugate")]
fn conjugate(&self, _vm: &VirtualMachine) -> Complex64 {
fn conjugate(&self) -> Complex64 {
self.value.conj()
}
@@ -184,12 +184,12 @@ impl PyComplex {
}
#[pymethod(name = "__neg__")]
fn neg(&self, _vm: &VirtualMachine) -> Complex64 {
fn neg(&self) -> Complex64 {
-self.value
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
let Complex64 { re, im } = self.value;
if re == 0.0 {
format!("{}j", im)
@@ -209,7 +209,7 @@ impl PyComplex {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!Complex64::is_zero(&self.value)
}
@@ -235,7 +235,7 @@ impl PyComplex {
}
#[pymethod(name = "__hash__")]
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
fn hash(&self) -> pyhash::PyHash {
let re_hash = pyhash::hash_float(self.value.re);
let im_hash = pyhash::hash_float(self.value.im);
let ret = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(pyhash::IMAG);

View File

@@ -105,7 +105,7 @@ impl PyCoroutine {
}
#[pymethod(name = "__await__")]
fn r#await(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyCoroutineWrapper {
fn r#await(zelf: PyRef<Self>) -> PyCoroutineWrapper {
PyCoroutineWrapper { coro: zelf }
}
}
@@ -125,7 +125,7 @@ impl PyValue for PyCoroutineWrapper {
#[pyimpl]
impl PyCoroutineWrapper {
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}

View File

@@ -121,7 +121,7 @@ impl PyDictRef {
}
#[pymethod(magic)]
fn bool(self, _vm: &VirtualMachine) -> bool {
fn bool(self) -> bool {
!self.entries.borrow().is_empty()
}
@@ -168,12 +168,12 @@ impl PyDictRef {
}
#[pymethod(magic)]
fn len(self, _vm: &VirtualMachine) -> usize {
fn len(self) -> usize {
self.entries.borrow().len()
}
#[pymethod(magic)]
fn sizeof(self, _vm: &VirtualMachine) -> usize {
fn sizeof(self) -> usize {
size_of::<Self>() + self.entries.borrow().sizeof()
}
@@ -205,27 +205,27 @@ impl PyDictRef {
}
#[pymethod]
fn clear(self, _vm: &VirtualMachine) {
fn clear(self) {
self.entries.borrow_mut().clear()
}
#[pymethod(magic)]
fn iter(self, _vm: &VirtualMachine) -> PyDictKeyIterator {
fn iter(self) -> PyDictKeyIterator {
PyDictKeyIterator::new(self)
}
#[pymethod]
fn keys(self, _vm: &VirtualMachine) -> PyDictKeys {
fn keys(self) -> PyDictKeys {
PyDictKeys::new(self)
}
#[pymethod]
fn values(self, _vm: &VirtualMachine) -> PyDictValues {
fn values(self) -> PyDictValues {
PyDictValues::new(self)
}
#[pymethod]
fn items(self, _vm: &VirtualMachine) -> PyDictItems {
fn items(self) -> PyDictItems {
PyDictItems::new(self)
}
@@ -305,7 +305,7 @@ impl PyDictRef {
}
#[pymethod]
pub fn copy(self, _vm: &VirtualMachine) -> PyDict {
pub fn copy(self) -> PyDict {
PyDict {
entries: self.entries.clone(),
}
@@ -508,13 +508,13 @@ macro_rules! dict_iterator {
}
#[pymethod(name = "__iter__")]
fn iter(&self, _vm: &VirtualMachine) -> $iter_name {
fn iter(&self) -> $iter_name {
$iter_name::new(self.dict.clone())
}
#[pymethod(name = "__len__")]
fn len(&self, vm: &VirtualMachine) -> usize {
self.dict.clone().len(vm)
fn len(&self) -> usize {
self.dict.clone().len()
}
#[pymethod(name = "__repr__")]
@@ -579,12 +579,12 @@ macro_rules! dict_iterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
#[pymethod(name = "__length_hint__")]
fn length_hint(&self, _vm: &VirtualMachine) -> usize {
fn length_hint(&self) -> usize {
self.dict
.entries
.borrow()

View File

@@ -21,10 +21,10 @@ fn ellipsis_new(cls: PyClassRef, vm: &VirtualMachine) -> PyResult {
}
}
fn ellipsis_repr(_self: PyEllipsisRef, _vm: &VirtualMachine) -> String {
fn ellipsis_repr(_self: PyEllipsisRef) -> String {
"Ellipsis".to_owned()
}
fn ellipsis_reduce(_self: PyEllipsisRef, _vm: &VirtualMachine) -> String {
fn ellipsis_reduce(_self: PyEllipsisRef) -> String {
"Ellipsis".to_owned()
}

View File

@@ -62,7 +62,7 @@ impl PyEnumerate {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -61,7 +61,7 @@ impl PyFilter {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -273,7 +273,7 @@ impl PyFloat {
}
#[pymethod(name = "__abs__")]
fn abs(&self, _vm: &VirtualMachine) -> f64 {
fn abs(&self) -> f64 {
self.value.abs()
}
@@ -315,7 +315,7 @@ impl PyFloat {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
self.value != 0.0
}
@@ -350,12 +350,12 @@ impl PyFloat {
}
#[pymethod(name = "__pos__")]
fn pos(&self, _vm: &VirtualMachine) -> f64 {
fn pos(&self) -> f64 {
self.value
}
#[pymethod(name = "__neg__")]
fn neg(&self, _vm: &VirtualMachine) -> f64 {
fn neg(&self) -> f64 {
-self.value
}
@@ -380,14 +380,14 @@ impl PyFloat {
}
#[pymethod(name = "__repr__")]
fn repr(&self, vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
let value = format!("{:e}", self.value);
if let Some(position) = value.find('e') {
let significand = &value[..position];
let exponent = &value[position + 1..];
let exponent = exponent.parse::<i32>().unwrap();
if exponent < 16 && exponent > -5 {
if self.is_integer(vm) {
if self.is_integer() {
format!("{:.1?}", self.value)
} else {
self.value.to_string()
@@ -489,32 +489,32 @@ impl PyFloat {
}
#[pymethod(name = "__float__")]
fn float(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyFloatRef {
fn float(zelf: PyRef<Self>) -> PyFloatRef {
zelf
}
#[pymethod(name = "__hash__")]
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
fn hash(&self) -> pyhash::PyHash {
pyhash::hash_float(self.value)
}
#[pyproperty]
fn real(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyFloatRef {
fn real(zelf: PyRef<Self>) -> PyFloatRef {
zelf
}
#[pyproperty]
fn imag(&self, _vm: &VirtualMachine) -> f64 {
fn imag(&self) -> f64 {
0.0f64
}
#[pymethod(name = "conjugate")]
fn conjugate(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyFloatRef {
fn conjugate(zelf: PyRef<Self>) -> PyFloatRef {
zelf
}
#[pymethod(name = "is_integer")]
fn is_integer(&self, _vm: &VirtualMachine) -> bool {
fn is_integer(&self) -> bool {
let v = self.value;
(v - v.round()).abs() < std::f64::EPSILON
}
@@ -592,7 +592,7 @@ impl PyFloat {
}
#[pymethod]
fn hex(&self, _vm: &VirtualMachine) -> String {
fn hex(&self) -> String {
to_hex(self.value)
}
}

View File

@@ -20,27 +20,27 @@ impl FrameRef {
}
#[pymethod(name = "__repr__")]
fn repr(self, _vm: &VirtualMachine) -> String {
fn repr(self) -> String {
"<frame object at .. >".to_owned()
}
#[pymethod]
fn clear(self, _vm: &VirtualMachine) {
fn clear(self) {
// TODO
}
#[pyproperty]
fn f_globals(self, _vm: &VirtualMachine) -> PyDictRef {
fn f_globals(self) -> PyDictRef {
self.scope.globals.clone()
}
#[pyproperty]
fn f_locals(self, _vm: &VirtualMachine) -> PyDictRef {
fn f_locals(self) -> PyDictRef {
self.scope.get_locals()
}
#[pyproperty]
fn f_code(self, _vm: &VirtualMachine) -> PyCodeRef {
fn f_code(self) -> PyCodeRef {
self.code.clone()
}

View File

@@ -250,17 +250,17 @@ impl PyFunction {
}
#[pyproperty(magic)]
fn code(&self, _vm: &VirtualMachine) -> PyCodeRef {
fn code(&self) -> PyCodeRef {
self.code.clone()
}
#[pyproperty(magic)]
fn defaults(&self, _vm: &VirtualMachine) -> Option<PyTupleRef> {
fn defaults(&self) -> Option<PyTupleRef> {
self.defaults.clone()
}
#[pyproperty(magic)]
fn kwdefaults(&self, _vm: &VirtualMachine) -> Option<PyDictRef> {
fn kwdefaults(&self) -> Option<PyDictRef> {
self.kw_only_defaults.clone()
}
}

View File

@@ -45,7 +45,7 @@ impl PyGenerator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyGeneratorRef, _vm: &VirtualMachine) -> PyGeneratorRef {
fn iter(zelf: PyGeneratorRef) -> PyGeneratorRef {
zelf
}

View File

@@ -413,17 +413,17 @@ impl PyInt {
}
#[pymethod(name = "__neg__")]
fn neg(&self, _vm: &VirtualMachine) -> BigInt {
fn neg(&self) -> BigInt {
-(&self.value)
}
#[pymethod(name = "__hash__")]
pub fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
pub fn hash(&self) -> pyhash::PyHash {
pyhash::hash_bigint(&self.value)
}
#[pymethod(name = "__abs__")]
fn abs(&self, _vm: &VirtualMachine) -> BigInt {
fn abs(&self) -> BigInt {
self.value.abs()
}
@@ -457,12 +457,12 @@ impl PyInt {
}
#[pymethod(name = "__int__")]
fn int(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn int(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pymethod(name = "__pos__")]
fn pos(&self, _vm: &VirtualMachine) -> BigInt {
fn pos(&self) -> BigInt {
self.value.clone()
}
@@ -472,32 +472,32 @@ impl PyInt {
}
#[pymethod(name = "__trunc__")]
fn trunc(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn trunc(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pymethod(name = "__floor__")]
fn floor(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn floor(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pymethod(name = "__ceil__")]
fn ceil(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn ceil(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pymethod(name = "__index__")]
fn index(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn index(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pymethod(name = "__invert__")]
fn invert(&self, _vm: &VirtualMachine) -> BigInt {
fn invert(&self) -> BigInt {
!(&self.value)
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
self.value.to_string()
}
@@ -512,22 +512,22 @@ impl PyInt {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!self.value.is_zero()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
size_of::<Self>() + ((self.value.bits() + 7) & !7) / 8
}
#[pymethod]
fn bit_length(&self, _vm: &VirtualMachine) -> usize {
fn bit_length(&self) -> usize {
self.value.bits()
}
#[pymethod]
fn conjugate(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn conjugate(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
@@ -631,17 +631,17 @@ impl PyInt {
}
#[pyproperty]
fn imag(&self, _vm: &VirtualMachine) -> usize {
fn imag(&self) -> usize {
0
}
#[pyproperty]
fn numerator(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyIntRef {
fn numerator(zelf: PyRef<Self>) -> PyIntRef {
zelf
}
#[pyproperty]
fn denominator(&self, _vm: &VirtualMachine) -> usize {
fn denominator(&self) -> usize {
1
}
}

View File

@@ -174,7 +174,7 @@ impl PySequenceIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -193,7 +193,7 @@ impl PySequenceIterator {
}
}
pub fn seq_iter_method(obj: PyObjectRef, _vm: &VirtualMachine) -> PySequenceIterator {
pub fn seq_iter_method(obj: PyObjectRef) -> PySequenceIterator {
PySequenceIterator {
position: Cell::new(0),
obj,

View File

@@ -147,7 +147,7 @@ pub type PyListRef = PyRef<PyList>;
#[pyimpl(flags(BASETYPE))]
impl PyList {
#[pymethod]
pub(crate) fn append(&self, x: PyObjectRef, _vm: &VirtualMachine) {
pub(crate) fn append(&self, x: PyObjectRef) {
self.elements.borrow_mut().push(x);
}
@@ -159,7 +159,7 @@ impl PyList {
}
#[pymethod]
fn insert(&self, position: isize, element: PyObjectRef, _vm: &VirtualMachine) {
fn insert(&self, position: isize, element: PyObjectRef) {
let mut vec = self.elements.borrow_mut();
let vec_len = vec.len().to_isize().unwrap();
// This unbounded position can be < 0 or > vec.len()
@@ -201,12 +201,12 @@ impl PyList {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!self.elements.borrow().is_empty()
}
#[pymethod]
fn clear(&self, _vm: &VirtualMachine) {
fn clear(&self) {
self.elements.borrow_mut().clear();
}
@@ -216,22 +216,22 @@ impl PyList {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.elements.borrow().len()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
size_of::<Self>() + self.elements.borrow().capacity() * size_of::<PyObjectRef>()
}
#[pymethod]
fn reverse(&self, _vm: &VirtualMachine) {
fn reverse(&self) {
self.elements.borrow_mut().reverse();
}
#[pymethod(name = "__reversed__")]
fn reversed(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyListReverseIterator {
fn reversed(zelf: PyRef<Self>) -> PyListReverseIterator {
let final_position = zelf.elements.borrow().len();
PyListReverseIterator {
position: Cell::new(final_position),
@@ -250,7 +250,7 @@ impl PyList {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyListIterator {
fn iter(zelf: PyRef<Self>) -> PyListIterator {
PyListIterator {
position: Cell::new(0),
list: zelf,
@@ -481,7 +481,7 @@ impl PyList {
}
#[pymethod(name = "__imul__")]
fn imul(zelf: PyRef<Self>, counter: isize, _vm: &VirtualMachine) -> PyRef<Self> {
fn imul(zelf: PyRef<Self>, counter: isize) -> PyRef<Self> {
let new_elements = sequence::seq_mul(&zelf.borrow_sequence(), counter)
.cloned()
.collect();
@@ -868,12 +868,12 @@ impl PyListIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
#[pymethod(name = "__length_hint__")]
fn length_hint(&self, _vm: &VirtualMachine) -> usize {
fn length_hint(&self) -> usize {
self.list.elements.borrow().len() - self.position.get()
}
}
@@ -906,12 +906,12 @@ impl PyListReverseIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
#[pymethod(name = "__length_hint__")]
fn length_hint(&self, _vm: &VirtualMachine) -> usize {
fn length_hint(&self) -> usize {
self.position.get()
}
}

View File

@@ -55,7 +55,7 @@ impl PyMap {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}

View File

@@ -40,12 +40,12 @@ impl PyNone {
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> PyResult<String> {
fn repr(&self) -> PyResult<String> {
Ok("None".to_owned())
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> PyResult<bool> {
fn bool(&self) -> PyResult<bool> {
Ok(false)
}

View File

@@ -37,7 +37,7 @@ impl PyBaseObject {
}
#[pymethod(magic)]
fn eq(zelf: PyObjectRef, other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue {
fn eq(zelf: PyObjectRef, other: PyObjectRef) -> PyComparisonValue {
if zelf.is(&other) {
Implemented(true)
} else {
@@ -64,27 +64,27 @@ impl PyBaseObject {
}
#[pymethod(magic)]
fn lt(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue {
fn lt(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue {
NotImplemented
}
#[pymethod(magic)]
fn le(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue {
fn le(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue {
NotImplemented
}
#[pymethod(magic)]
fn gt(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue {
fn gt(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue {
NotImplemented
}
#[pymethod(magic)]
fn ge(_zelf: PyObjectRef, _other: PyObjectRef, _vm: &VirtualMachine) -> PyComparisonValue {
fn ge(_zelf: PyObjectRef, _other: PyObjectRef) -> PyComparisonValue {
NotImplemented
}
#[pymethod(magic)]
fn hash(zelf: PyObjectRef, _vm: &VirtualMachine) -> pyhash::PyHash {
fn hash(zelf: PyObjectRef) -> pyhash::PyHash {
zelf.get_id() as pyhash::PyHash
}
@@ -126,7 +126,7 @@ impl PyBaseObject {
}
#[pymethod(magic)]
fn repr(zelf: PyObjectRef, _vm: &VirtualMachine) -> String {
fn repr(zelf: PyObjectRef) -> String {
format!("<{} object at 0x{:x}>", zelf.class().name, zelf.get_id())
}
@@ -175,7 +175,7 @@ impl PyBaseObject {
}
#[pyproperty(name = "__class__")]
fn get_class(obj: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef {
fn get_class(obj: PyObjectRef) -> PyObjectRef {
obj.class().into_object()
}

View File

@@ -129,21 +129,21 @@ impl PyProperty {
// Access functions
#[pyproperty]
fn fget(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
fn fget(&self) -> Option<PyObjectRef> {
self.getter.clone()
}
#[pyproperty]
fn fset(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
fn fset(&self) -> Option<PyObjectRef> {
self.setter.clone()
}
#[pyproperty]
fn fdel(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
fn fdel(&self) -> Option<PyObjectRef> {
self.deleter.clone()
}
fn doc_getter(&self, _vm: &VirtualMachine) -> Option<PyObjectRef> {
fn doc_getter(&self) -> Option<PyObjectRef> {
self.doc.borrow().clone()
}

View File

@@ -154,22 +154,22 @@ impl PyRange {
}
#[pyproperty(name = "start")]
fn start(&self, _vm: &VirtualMachine) -> PyIntRef {
fn start(&self) -> PyIntRef {
self.start.clone()
}
#[pyproperty(name = "stop")]
fn stop(&self, _vm: &VirtualMachine) -> PyIntRef {
fn stop(&self) -> PyIntRef {
self.stop.clone()
}
#[pyproperty(name = "step")]
fn step(&self, _vm: &VirtualMachine) -> PyIntRef {
fn step(&self) -> PyIntRef {
self.step.clone()
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRangeIterator {
fn iter(zelf: PyRef<Self>) -> PyRangeIterator {
PyRangeIterator {
position: Cell::new(0),
range: zelf,
@@ -210,12 +210,12 @@ impl PyRange {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> BigInt {
fn len(&self) -> BigInt {
self.length()
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
if self.step.as_bigint().is_one() {
format!("range({}, {})", self.start, self.stop)
} else {
@@ -224,12 +224,12 @@ impl PyRange {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!self.is_empty()
}
#[pymethod(name = "__contains__")]
fn contains(&self, needle: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn contains(&self, needle: PyObjectRef) -> bool {
if let Ok(int) = needle.downcast::<PyInt>() {
match self.offset(int.as_bigint()) {
Some(ref offset) => offset.is_multiple_of(self.step.as_bigint()),
@@ -323,7 +323,7 @@ impl PyRange {
}
#[pymethod(name = "count")]
fn count(&self, item: PyObjectRef, _vm: &VirtualMachine) -> usize {
fn count(&self, item: PyObjectRef) -> usize {
if let Ok(int) = item.downcast::<PyInt>() {
if self.index_of(int.as_bigint()).is_some() {
1
@@ -341,8 +341,8 @@ impl PyRange {
RangeIndex::Slice(slice) => {
let (mut substart, mut substop, mut substep) =
slice.inner_indices(&self.length(), vm)?;
let range_step = self.step(vm);
let range_start = self.start(vm);
let range_step = &self.step;
let range_start = &self.start;
substep *= range_step.as_bigint();
substart = (substart * range_step.as_bigint()) + range_start.as_bigint();
@@ -371,14 +371,14 @@ impl PyRange {
} else if length.is_one() {
vec![
vm.ctx.new_int(length),
zelf.start(vm).into_object(),
zelf.start().into_object(),
vm.get_none(),
]
} else {
vec![
vm.ctx.new_int(length),
zelf.start(vm).into_object(),
zelf.step(vm).into_object(),
zelf.start().into_object(),
zelf.step().into_object(),
]
};
pyhash::hash_iter(elements.iter(), vm)
@@ -427,7 +427,7 @@ impl PyRangeIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRangeIteratorRef {
fn iter(zelf: PyRef<Self>) -> PyRangeIteratorRef {
zelf
}
}

View File

@@ -343,17 +343,17 @@ impl PySet {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.inner.borrow().len()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
std::mem::size_of::<Self>() + self.inner.borrow().sizeof()
}
#[pymethod]
fn copy(&self, _vm: &VirtualMachine) -> Self {
fn copy(&self) -> Self {
Self {
inner: RefCell::new(self.inner.borrow().copy()),
}
@@ -513,7 +513,7 @@ impl PySet {
}
#[pymethod]
fn clear(&self, _vm: &VirtualMachine) {
fn clear(&self) {
self.inner.borrow_mut().clear()
}
@@ -599,17 +599,17 @@ impl PyFrozenSet {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.inner.len()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
std::mem::size_of::<Self>() + self.inner.sizeof()
}
#[pymethod]
fn copy(&self, _vm: &VirtualMachine) -> Self {
fn copy(&self) -> Self {
Self {
inner: self.inner.copy(),
}

View File

@@ -51,14 +51,14 @@ impl PySlice {
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> PyResult<String> {
let start = self.start(_vm);
let stop = self.stop(_vm);
let step = self.step(_vm);
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
let start = self.start(vm);
let stop = self.stop(vm);
let step = self.step(vm);
let start_repr = _vm.to_repr(&start)?;
let stop_repr = _vm.to_repr(&stop)?;
let step_repr = _vm.to_repr(&step)?;
let start_repr = vm.to_repr(&start)?;
let stop_repr = vm.to_repr(&stop)?;
let step_repr = vm.to_repr(&step)?;
Ok(format!(
"slice({}, {}, {})",

View File

@@ -127,7 +127,7 @@ impl PyStringIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -163,7 +163,7 @@ impl PyStringReverseIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -225,7 +225,7 @@ impl PyString {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!self.value.is_empty()
}
@@ -248,7 +248,7 @@ impl PyString {
}
#[pymethod(name = "__contains__")]
fn contains(&self, needle: PyStringRef, _vm: &VirtualMachine) -> bool {
fn contains(&self, needle: PyStringRef) -> bool {
self.value.contains(&needle.value)
}
@@ -285,27 +285,27 @@ impl PyString {
}
#[pymethod(name = "__gt__")]
fn gt(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool {
fn gt(&self, other: PyStringRef) -> bool {
self.value > other.value
}
#[pymethod(name = "__ge__")]
fn ge(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool {
fn ge(&self, other: PyStringRef) -> bool {
self.value >= other.value
}
#[pymethod(name = "__lt__")]
fn lt(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool {
fn lt(&self, other: PyStringRef) -> bool {
self.value < other.value
}
#[pymethod(name = "__le__")]
fn le(&self, other: PyStringRef, _vm: &VirtualMachine) -> bool {
fn le(&self, other: PyStringRef) -> bool {
self.value <= other.value
}
#[pymethod(name = "__hash__")]
fn hash(&self, _vm: &VirtualMachine) -> pyhash::PyHash {
fn hash(&self) -> pyhash::PyHash {
match self.hash.get() {
Some(hash) => hash,
None => {
@@ -317,12 +317,12 @@ impl PyString {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.value.chars().count()
}
#[pymethod(name = "__sizeof__")]
fn sizeof(&self, _vm: &VirtualMachine) -> usize {
fn sizeof(&self) -> usize {
size_of::<Self>() + self.value.capacity() * size_of::<u8>()
}
@@ -343,12 +343,12 @@ impl PyString {
}
#[pymethod(name = "__str__")]
fn str(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyStringRef {
fn str(zelf: PyRef<Self>) -> PyStringRef {
zelf
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
let value = &self.value;
let quote_char = if count_char(value, '\'') > count_char(value, '"') {
'"'
@@ -390,23 +390,23 @@ impl PyString {
}
#[pymethod]
fn lower(&self, _vm: &VirtualMachine) -> String {
fn lower(&self) -> String {
self.value.to_lowercase()
}
// casefold is much more aggressive than lower
#[pymethod]
fn casefold(&self, _vm: &VirtualMachine) -> String {
fn casefold(&self) -> String {
caseless::default_case_fold_str(&self.value)
}
#[pymethod]
fn upper(&self, _vm: &VirtualMachine) -> String {
fn upper(&self) -> String {
self.value.to_uppercase()
}
#[pymethod]
fn capitalize(&self, _vm: &VirtualMachine) -> String {
fn capitalize(&self) -> String {
let (first_part, lower_str) = self.value.split_at(1);
format!("{}{}", first_part.to_uppercase(), lower_str)
}
@@ -471,7 +471,7 @@ impl PyString {
}
#[pymethod]
fn strip(&self, chars: OptionalArg<PyStringRef>, _vm: &VirtualMachine) -> String {
fn strip(&self, chars: OptionalArg<PyStringRef>) -> String {
let chars = match chars {
OptionalArg::Present(ref chars) => &chars.value,
OptionalArg::Missing => return self.value.trim().to_owned(),
@@ -480,7 +480,7 @@ impl PyString {
}
#[pymethod]
fn lstrip(&self, chars: OptionalArg<PyStringRef>, _vm: &VirtualMachine) -> String {
fn lstrip(&self, chars: OptionalArg<PyStringRef>) -> String {
let chars = match chars {
OptionalArg::Present(ref chars) => &chars.value,
OptionalArg::Missing => return self.value.trim_start().to_owned(),
@@ -491,7 +491,7 @@ impl PyString {
}
#[pymethod]
fn rstrip(&self, chars: OptionalArg<PyStringRef>, _vm: &VirtualMachine) -> String {
fn rstrip(&self, chars: OptionalArg<PyStringRef>) -> String {
let chars = match chars {
OptionalArg::Present(ref chars) => &chars.value,
OptionalArg::Missing => return self.value.trim_end().to_owned(),
@@ -554,17 +554,17 @@ impl PyString {
}
#[pymethod]
fn isalnum(&self, _vm: &VirtualMachine) -> bool {
fn isalnum(&self) -> bool {
!self.value.is_empty() && self.value.chars().all(char::is_alphanumeric)
}
#[pymethod]
fn isnumeric(&self, _vm: &VirtualMachine) -> bool {
fn isnumeric(&self) -> bool {
!self.value.is_empty() && self.value.chars().all(char::is_numeric)
}
#[pymethod]
fn isdigit(&self, _vm: &VirtualMachine) -> bool {
fn isdigit(&self) -> bool {
// python's isdigit also checks if exponents are digits, these are the unicodes for exponents
let valid_unicodes: [u16; 10] = [
0x2070, 0x00B9, 0x00B2, 0x00B3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079,
@@ -581,7 +581,7 @@ impl PyString {
}
#[pymethod]
fn isdecimal(&self, _vm: &VirtualMachine) -> bool {
fn isdecimal(&self) -> bool {
if self.value.is_empty() {
false
} else {
@@ -660,7 +660,7 @@ impl PyString {
/// Return a titlecased version of the string where words start with an
/// uppercase character and the remaining characters are lowercase.
#[pymethod]
fn title(&self, _vm: &VirtualMachine) -> String {
fn title(&self) -> String {
let mut title = String::with_capacity(self.value.len());
let mut previous_is_cased = false;
for c in self.value.chars() {
@@ -687,7 +687,7 @@ impl PyString {
}
#[pymethod]
fn swapcase(&self, _vm: &VirtualMachine) -> String {
fn swapcase(&self) -> String {
let mut swapped_str = String::with_capacity(self.value.len());
for c in self.value.chars() {
// to_uppercase returns an iterator, to_ascii_uppercase returns the char
@@ -703,18 +703,12 @@ impl PyString {
}
#[pymethod]
fn isalpha(&self, _vm: &VirtualMachine) -> bool {
fn isalpha(&self) -> bool {
!self.value.is_empty() && self.value.chars().all(char::is_alphanumeric)
}
#[pymethod]
fn replace(
&self,
old: PyStringRef,
new: PyStringRef,
num: OptionalArg<usize>,
_vm: &VirtualMachine,
) -> String {
fn replace(&self, old: PyStringRef, new: PyStringRef, num: OptionalArg<usize>) -> String {
match num.into_option() {
Some(num) => self.value.replacen(&old.value, &new.value, num),
None => self.value.replace(&old.value, &new.value),
@@ -737,7 +731,7 @@ impl PyString {
/// * Zp Separator, Paragraph ('\u2029', PARAGRAPH SEPARATOR)
/// * Zs (Separator, Space) other than ASCII space('\x20').
#[pymethod]
fn isprintable(&self, _vm: &VirtualMachine) -> bool {
fn isprintable(&self) -> bool {
self.value
.chars()
.all(|c| c == '\u{0020}' || char_is_printable(c))
@@ -746,13 +740,13 @@ impl PyString {
// cpython's isspace ignores whitespace, including \t and \n, etc, unless the whole string is empty
// which is why isspace is using is_ascii_whitespace. Same for isupper & islower
#[pymethod]
fn isspace(&self, _vm: &VirtualMachine) -> bool {
fn isspace(&self) -> bool {
!self.value.is_empty() && self.value.chars().all(|c| c.is_ascii_whitespace())
}
// Return true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise.
#[pymethod]
fn isupper(&self, _vm: &VirtualMachine) -> bool {
fn isupper(&self) -> bool {
let mut cased = false;
for c in self.value.chars() {
if is_cased(c) && c.is_uppercase() {
@@ -766,7 +760,7 @@ impl PyString {
// Return true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise.
#[pymethod]
fn islower(&self, _vm: &VirtualMachine) -> bool {
fn islower(&self) -> bool {
let mut cased = false;
for c in self.value.chars() {
if is_cased(c) && c.is_lowercase() {
@@ -779,7 +773,7 @@ impl PyString {
}
#[pymethod]
fn isascii(&self, _vm: &VirtualMachine) -> bool {
fn isascii(&self) -> bool {
!self.value.is_empty() && self.value.chars().all(|c| c.is_ascii())
}
@@ -821,13 +815,7 @@ impl PyString {
}
#[pymethod]
fn find(
&self,
sub: PyStringRef,
start: OptionalArg<isize>,
end: OptionalArg<isize>,
_vm: &VirtualMachine,
) -> isize {
fn find(&self, sub: PyStringRef, start: OptionalArg<isize>, end: OptionalArg<isize>) -> isize {
let value = &self.value;
if let Some((start, end)) = adjust_indices(start, end, value.len()) {
match value[start..end].find(&sub.value) {
@@ -840,13 +828,7 @@ impl PyString {
}
#[pymethod]
fn rfind(
&self,
sub: PyStringRef,
start: OptionalArg<isize>,
end: OptionalArg<isize>,
_vm: &VirtualMachine,
) -> isize {
fn rfind(&self, sub: PyStringRef, start: OptionalArg<isize>, end: OptionalArg<isize>) -> isize {
let value = &self.value;
if let Some((start, end)) = adjust_indices(start, end, value.len()) {
match value[start..end].rfind(&sub.value) {
@@ -938,7 +920,7 @@ impl PyString {
/// Return `true` if the sequence is ASCII titlecase and the sequence is not
/// empty, `false` otherwise.
#[pymethod]
fn istitle(&self, _vm: &VirtualMachine) -> bool {
fn istitle(&self) -> bool {
if self.value.is_empty() {
return false;
}
@@ -966,13 +948,7 @@ impl PyString {
}
#[pymethod]
fn count(
&self,
sub: PyStringRef,
start: OptionalArg<isize>,
end: OptionalArg<isize>,
_vm: &VirtualMachine,
) -> usize {
fn count(&self, sub: PyStringRef, start: OptionalArg<isize>, end: OptionalArg<isize>) -> usize {
let value = &self.value;
if let Some((start, end)) = adjust_indices(start, end, value.len()) {
self.value[start..end].matches(&sub.value).count()
@@ -982,7 +958,7 @@ impl PyString {
}
#[pymethod]
fn zfill(&self, len: usize, _vm: &VirtualMachine) -> String {
fn zfill(&self, len: usize) -> String {
let value = &self.value;
if len <= value.len() {
value.to_owned()
@@ -1073,7 +1049,7 @@ impl PyString {
}
#[pymethod]
fn expandtabs(&self, tab_stop: OptionalArg<usize>, _vm: &VirtualMachine) -> String {
fn expandtabs(&self, tab_stop: OptionalArg<usize>) -> String {
let tab_stop = tab_stop.into_option().unwrap_or(8 as usize);
let mut expanded_str = String::with_capacity(self.value.len());
let mut tab_size = tab_stop;
@@ -1097,7 +1073,7 @@ impl PyString {
}
#[pymethod]
fn isidentifier(&self, _vm: &VirtualMachine) -> bool {
fn isidentifier(&self) -> bool {
let mut chars = self.value.chars();
let is_identifier_start = chars.next().map_or(false, |c| c == '_' || is_xid_start(c));
// a string is not an identifier if it has whitespace or starts with a number
@@ -1151,7 +1127,7 @@ impl PyString {
if let OptionalArg::Present(to_str) = to_str {
match dict_or_str.downcast::<PyString>() {
Ok(from_str) => {
if to_str.len(vm) == from_str.len(vm) {
if to_str.len() == from_str.len() {
for (c1, c2) in from_str.value.chars().zip(to_str.value.chars()) {
new_dict.set_item(&vm.new_int(c1 as u32), vm.new_int(c2 as u32), vm)?;
}
@@ -1184,7 +1160,7 @@ impl PyString {
vm,
)?;
} else if let Some(string) = key.payload::<PyString>() {
if string.len(vm) == 1 {
if string.len() == 1 {
let num_value = string.value.chars().next().unwrap() as u32;
new_dict.set_item(&num_value.into_pyobject(vm)?, val, vm)?;
} else {
@@ -1214,7 +1190,7 @@ impl PyString {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyStringIterator {
fn iter(zelf: PyRef<Self>) -> PyStringIterator {
PyStringIterator {
byte_position: Cell::new(0),
string: zelf,
@@ -1222,7 +1198,7 @@ impl PyString {
}
#[pymethod(name = "__reversed__")]
fn reversed(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyStringReverseIterator {
fn reversed(zelf: PyRef<Self>) -> PyStringReverseIterator {
let begin = zelf.value.chars().count();
PyStringReverseIterator {
@@ -1735,7 +1711,7 @@ mod tests {
("Greek ῼitlecases ...", "greek ῳitlecases ..."),
];
for (title, input) in tests {
assert_eq!(PyString::from(input).title(&vm).as_str(), title);
assert_eq!(PyString::from(input).title().as_str(), title);
}
}
@@ -1753,7 +1729,7 @@ mod tests {
];
for s in pos {
assert!(PyString::from(s).istitle(&vm));
assert!(PyString::from(s).istitle());
}
let neg = vec![
@@ -1766,7 +1742,7 @@ mod tests {
"NOT",
];
for s in neg {
assert!(!PyString::from(s).istitle(&vm));
assert!(!PyString::from(s).istitle());
}
}

View File

@@ -35,7 +35,7 @@ impl PyValue for PySuper {
#[pyimpl]
impl PySuper {
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
let class_type_str = if let Ok(type_class) = self.typ.clone().downcast::<PyClass>() {
type_class.name.clone()
} else {

View File

@@ -32,22 +32,22 @@ impl PyTraceback {
}
#[pyproperty(name = "tb_frame")]
fn frame(&self, _vm: &VirtualMachine) -> FrameRef {
fn frame(&self) -> FrameRef {
self.frame.clone()
}
#[pyproperty(name = "tb_lasti")]
fn lasti(&self, _vm: &VirtualMachine) -> usize {
fn lasti(&self) -> usize {
self.lasti
}
#[pyproperty(name = "tb_lineno")]
fn lineno(&self, _vm: &VirtualMachine) -> usize {
fn lineno(&self) -> usize {
self.lineno
}
#[pyproperty(name = "tb_next")]
fn next_get(&self, _vm: &VirtualMachine) -> Option<PyTracebackRef> {
fn next_get(&self) -> Option<PyTracebackRef> {
self.next.as_ref().cloned()
}
}

View File

@@ -127,7 +127,7 @@ impl PyTuple {
}
#[pymethod(name = "__bool__")]
fn bool(&self, _vm: &VirtualMachine) -> bool {
fn bool(&self) -> bool {
!self.elements.is_empty()
}
@@ -158,7 +158,7 @@ impl PyTuple {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyTupleIterator {
fn iter(zelf: PyRef<Self>) -> PyTupleIterator {
PyTupleIterator {
position: Cell::new(0),
tuple: zelf,
@@ -166,7 +166,7 @@ impl PyTuple {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.elements.len()
}
@@ -191,18 +191,14 @@ impl PyTuple {
}
#[pymethod(name = "__mul__")]
fn mul(&self, counter: isize, _vm: &VirtualMachine) -> PyTuple {
#[pymethod(name = "__rmul__")]
fn mul(&self, counter: isize) -> PyTuple {
let new_elements: Vec<_> = sequence::seq_mul(&self.elements, counter)
.cloned()
.collect();
new_elements.into()
}
#[pymethod(name = "__rmul__")]
fn rmul(&self, counter: isize, vm: &VirtualMachine) -> PyTuple {
self.mul(counter, vm)
}
#[pymethod(name = "__getitem__")]
fn getitem(zelf: PyRef<Self>, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult {
get_item(vm, zelf.as_object(), &zelf.elements, needle.clone())
@@ -271,7 +267,7 @@ impl PyTupleIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -80,7 +80,7 @@ impl PyClassRef {
}
#[pyproperty(name = "__mro__")]
fn get_mro(self, _vm: &VirtualMachine) -> PyTuple {
fn get_mro(self) -> PyTuple {
let elements: Vec<PyObjectRef> =
_mro(&self).iter().map(|x| x.as_object().clone()).collect();
PyTuple::from(elements)
@@ -103,22 +103,22 @@ impl PyClassRef {
}
#[pymethod(magic)]
fn instancecheck(self, obj: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn instancecheck(self, obj: PyObjectRef) -> bool {
isinstance(&obj, &self)
}
#[pymethod(magic)]
fn subclasscheck(self, subclass: PyClassRef, _vm: &VirtualMachine) -> bool {
fn subclasscheck(self, subclass: PyClassRef) -> bool {
issubclass(&subclass, &self)
}
#[pyproperty(magic)]
fn name(self, _vm: &VirtualMachine) -> String {
fn name(self) -> String {
self.name.clone()
}
#[pymethod(magic)]
fn repr(self, _vm: &VirtualMachine) -> String {
fn repr(self) -> String {
format!("<class '{}'>", self.name)
}
@@ -239,7 +239,7 @@ impl PyClassRef {
}
#[pymethod(magic)]
fn subclasses(self, _vm: &VirtualMachine) -> PyList {
fn subclasses(self) -> PyList {
let mut subclasses = self.subclasses.borrow_mut();
subclasses.retain(|x| x.upgrade().is_some());
PyList::from(

View File

@@ -45,7 +45,7 @@ impl PyZip {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -217,12 +217,12 @@ impl PyArray {
}
#[pyproperty]
fn typecode(&self, _vm: &VirtualMachine) -> String {
fn typecode(&self) -> String {
self.array.borrow().typecode().to_string()
}
#[pyproperty]
fn itemsize(&self, _vm: &VirtualMachine) -> usize {
fn itemsize(&self) -> usize {
self.array.borrow().itemsize()
}
@@ -232,7 +232,7 @@ impl PyArray {
}
#[pymethod]
fn buffer_info(&self, _vm: &VirtualMachine) -> (usize, usize) {
fn buffer_info(&self) -> (usize, usize) {
let array = self.array.borrow();
(array.addr(), array.len())
}
@@ -301,7 +301,7 @@ impl PyArray {
}
#[pymethod]
fn tobytes(&self, _vm: &VirtualMachine) -> Vec<u8> {
fn tobytes(&self) -> Vec<u8> {
self.array.borrow().tobytes()
}
@@ -316,7 +316,7 @@ impl PyArray {
}
#[pymethod]
fn reverse(&self, _vm: &VirtualMachine) {
fn reverse(&self) {
self.array.borrow_mut().reverse()
}
@@ -349,12 +349,12 @@ impl PyArray {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.array.borrow().len()
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyArrayIter {
fn iter(zelf: PyRef<Self>) -> PyArrayIter {
PyArrayIter {
position: Cell::new(0),
array: zelf,
@@ -394,7 +394,7 @@ impl PyArrayIter {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -56,7 +56,7 @@ fn hex_nibble(n: u8) -> u8 {
}
}
fn binascii_hexlify(data: PyBytesLike, _vm: &VirtualMachine) -> Vec<u8> {
fn binascii_hexlify(data: PyBytesLike) -> Vec<u8> {
data.with_ref(|bytes| {
let mut hex = Vec::<u8>::with_capacity(bytes.len() * 2);
for b in bytes.iter() {
@@ -124,11 +124,7 @@ fn binascii_a2b_base64(s: SerializedData, vm: &VirtualMachine) -> PyResult<Vec<u
.map_err(|err| vm.new_value_error(format!("error decoding base64: {}", err)))
}
fn binascii_b2a_base64(
data: PyBytesLike,
NewlineArg { newline }: NewlineArg,
_vm: &VirtualMachine,
) -> Vec<u8> {
fn binascii_b2a_base64(data: PyBytesLike, NewlineArg { newline }: NewlineArg) -> Vec<u8> {
let mut encoded = data.with_ref(base64::encode).into_bytes();
if newline {
encoded.push(b'\n');

View File

@@ -57,7 +57,7 @@ impl PyDeque {
}
#[pymethod]
fn append(&self, obj: PyObjectRef, _vm: &VirtualMachine) {
fn append(&self, obj: PyObjectRef) {
let mut deque = self.deque.borrow_mut();
if self.maxlen.get() == Some(deque.len()) {
deque.pop_front();
@@ -66,7 +66,7 @@ impl PyDeque {
}
#[pymethod]
fn appendleft(&self, obj: PyObjectRef, _vm: &VirtualMachine) {
fn appendleft(&self, obj: PyObjectRef) {
let mut deque = self.deque.borrow_mut();
if self.maxlen.get() == Some(deque.len()) {
deque.pop_back();
@@ -75,12 +75,12 @@ impl PyDeque {
}
#[pymethod]
fn clear(&self, _vm: &VirtualMachine) {
fn clear(&self) {
self.deque.borrow_mut().clear()
}
#[pymethod]
fn copy(&self, _vm: &VirtualMachine) -> Self {
fn copy(&self) -> Self {
self.clone()
}
@@ -99,7 +99,7 @@ impl PyDeque {
fn extend(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult<()> {
// TODO: use length_hint here and for extendleft
for elem in iter.iter(vm)? {
self.append(elem?, vm);
self.append(elem?);
}
Ok(())
}
@@ -107,7 +107,7 @@ impl PyDeque {
#[pymethod]
fn extendleft(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult<()> {
for elem in iter.iter(vm)? {
self.appendleft(elem?, vm);
self.appendleft(elem?);
}
Ok(())
}
@@ -191,13 +191,13 @@ impl PyDeque {
}
#[pymethod]
fn reverse(&self, _vm: &VirtualMachine) {
fn reverse(&self) {
self.deque
.replace_with(|deque| deque.iter().cloned().rev().collect());
}
#[pymethod]
fn rotate(&self, mid: OptionalArg<isize>, _vm: &VirtualMachine) {
fn rotate(&self, mid: OptionalArg<isize>) {
let mut deque = self.deque.borrow_mut();
let mid = mid.unwrap_or(1);
if mid < 0 {
@@ -208,12 +208,12 @@ impl PyDeque {
}
#[pyproperty]
fn maxlen(&self, _vm: &VirtualMachine) -> Option<usize> {
fn maxlen(&self) -> Option<usize> {
self.maxlen.get()
}
#[pyproperty(setter)]
fn set_maxlen(&self, maxlen: Option<usize>, _vm: &VirtualMachine) {
fn set_maxlen(&self, maxlen: Option<usize>) {
self.maxlen.set(maxlen);
}
@@ -326,7 +326,7 @@ impl PyDeque {
}
#[pymethod(name = "__mul__")]
fn mul(&self, n: isize, _vm: &VirtualMachine) -> Self {
fn mul(&self, n: isize) -> Self {
let deque: &VecDeque<_> = &self.deque.borrow();
let mul = sequence::seq_mul(deque, n);
let skipped = if let Some(maxlen) = self.maxlen.get() {
@@ -342,12 +342,12 @@ impl PyDeque {
}
#[pymethod(name = "__len__")]
fn len(&self, _vm: &VirtualMachine) -> usize {
fn len(&self) -> usize {
self.deque.borrow().len()
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyDequeIterator {
fn iter(zelf: PyRef<Self>) -> PyDequeIterator {
PyDequeIterator {
position: Cell::new(0),
deque: zelf,
@@ -382,7 +382,7 @@ impl PyDequeIterator {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -20,7 +20,7 @@ fn dump_traceback(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, vm:
}
}
fn enable(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, _vm: &VirtualMachine) {
fn enable(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>) {
// TODO
}
@@ -29,7 +29,6 @@ fn register(
_file: OptionalArg<i64>,
_all_threads: OptionalArg<bool>,
_chain: OptionalArg<bool>,
_vm: &VirtualMachine,
) {
// TODO
}

View File

@@ -49,7 +49,7 @@ impl PyHasher {
}
#[pyproperty(name = "name")]
fn name(&self, _vm: &VirtualMachine) -> String {
fn name(&self) -> String {
self.name.clone()
}
@@ -65,13 +65,13 @@ impl PyHasher {
}
#[pymethod(name = "digest")]
fn digest(&self, _vm: &VirtualMachine) -> PyBytes {
fn digest(&self) -> PyBytes {
let result = self.get_digest();
PyBytes::new(result)
}
#[pymethod(name = "hexdigest")]
fn hexdigest(&self, _vm: &VirtualMachine) -> String {
fn hexdigest(&self) -> String {
let result = self.get_digest();
hex::encode(result)
}

View File

@@ -47,7 +47,7 @@ fn imp_create_builtin(spec: PyObjectRef, vm: &VirtualMachine) -> PyResult {
}
}
fn imp_exec_builtin(_mod: PyModuleRef, _vm: &VirtualMachine) -> i32 {
fn imp_exec_builtin(_mod: PyModuleRef) -> i32 {
// TOOD: Should we do something here?
0
}
@@ -80,7 +80,7 @@ fn imp_is_frozen_package(name: PyStringRef, vm: &VirtualMachine) -> PyResult<boo
})
}
fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef, _vm: &VirtualMachine) {
fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef) {
// TODO:
}

View File

@@ -149,7 +149,7 @@ impl PyStringIORef {
}
}
fn seekable(self, _vm: &VirtualMachine) -> bool {
fn seekable(self) -> bool {
true
}
@@ -186,11 +186,11 @@ impl PyStringIORef {
Ok(())
}
fn closed(self, _vm: &VirtualMachine) -> bool {
fn closed(self) -> bool {
self.buffer.borrow().is_none()
}
fn close(self, _vm: &VirtualMachine) {
fn close(self) {
self.buffer.replace(None);
}
}
@@ -271,7 +271,7 @@ impl PyBytesIORef {
}
}
fn seekable(self, _vm: &VirtualMachine) -> bool {
fn seekable(self) -> bool {
true
}
@@ -293,11 +293,11 @@ impl PyBytesIORef {
Ok(())
}
fn closed(self, _vm: &VirtualMachine) -> bool {
fn closed(self) -> bool {
self.buffer.borrow().is_none()
}
fn close(self, _vm: &VirtualMachine) {
fn close(self) {
self.buffer.replace(None);
}
}
@@ -318,7 +318,7 @@ fn bytes_io_new(
.into_ref_with_type(vm, cls)
}
fn io_base_cm_enter(instance: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef {
fn io_base_cm_enter(instance: PyObjectRef) -> PyObjectRef {
instance.clone()
}
@@ -328,15 +328,15 @@ fn io_base_cm_exit(instance: PyObjectRef, _args: PyFuncArgs, vm: &VirtualMachine
}
// TODO Check if closed, then if so raise ValueError
fn io_base_flush(_self: PyObjectRef, _vm: &VirtualMachine) {}
fn io_base_flush(_self: PyObjectRef) {}
fn io_base_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn io_base_seekable(_self: PyObjectRef) -> bool {
false
}
fn io_base_readable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn io_base_readable(_self: PyObjectRef) -> bool {
false
}
fn io_base_writable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn io_base_writable(_self: PyObjectRef) -> bool {
false
}
@@ -435,7 +435,7 @@ fn io_base_checkseekable(
}
}
fn io_base_iter(instance: PyObjectRef, _vm: &VirtualMachine) -> PyObjectRef {
fn io_base_iter(instance: PyObjectRef) -> PyObjectRef {
instance
}
fn io_base_next(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult {
@@ -505,7 +505,7 @@ fn buffered_reader_read(
)
}
fn buffered_reader_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn buffered_reader_seekable(_self: PyObjectRef) -> bool {
true
}
@@ -680,7 +680,7 @@ mod fileio {
Ok(())
}
fn file_io_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn file_io_seekable(_self: PyObjectRef) -> bool {
true
}
@@ -709,7 +709,7 @@ fn buffered_writer_write(instance: PyObjectRef, obj: PyObjectRef, vm: &VirtualMa
vm.call_method(&raw, "write", vec![obj.clone()])
}
fn buffered_writer_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn buffered_writer_seekable(_self: PyObjectRef) -> bool {
true
}
@@ -722,7 +722,7 @@ fn text_io_wrapper_init(
Ok(())
}
fn text_io_wrapper_seekable(_self: PyObjectRef, _vm: &VirtualMachine) -> bool {
fn text_io_wrapper_seekable(_self: PyObjectRef) -> bool {
true
}

View File

@@ -67,7 +67,7 @@ impl PyItertoolsChain {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -134,7 +134,7 @@ impl PyItertoolsCompress {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -178,14 +178,14 @@ impl PyItertoolsCount {
}
#[pymethod(name = "__next__")]
fn next(&self, _vm: &VirtualMachine) -> PyResult<PyInt> {
fn next(&self) -> PyResult<PyInt> {
let result = self.cur.borrow().clone();
*self.cur.borrow_mut() += &self.step;
Ok(PyInt::new(result))
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -252,7 +252,7 @@ impl PyItertoolsCycle {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -304,7 +304,7 @@ impl PyItertoolsRepeat {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -353,7 +353,7 @@ impl PyItertoolsStarmap {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -412,7 +412,7 @@ impl PyItertoolsTakewhile {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -470,7 +470,7 @@ impl PyItertoolsDropwhile {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -596,7 +596,7 @@ impl PyItertoolsIslice {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -652,7 +652,7 @@ impl PyItertoolsFilterFalse {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -711,7 +711,7 @@ impl PyItertoolsAccumulate {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -810,7 +810,7 @@ impl PyItertoolsTee {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -927,7 +927,7 @@ impl PyItertoolsProduct {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}
@@ -977,7 +977,7 @@ impl PyItertoolsCombinations {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -1076,7 +1076,7 @@ impl PyItertoolsCombinationsWithReplacement {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -1184,7 +1184,7 @@ impl PyItertoolsPermutations {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
@@ -1333,7 +1333,7 @@ impl PyItertoolsZiplongest {
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
}

View File

@@ -4,7 +4,7 @@ use crate::obj::objcode::{PyCode, PyCodeRef};
use crate::pyobject::{PyObjectRef, PyResult};
use crate::vm::VirtualMachine;
fn marshal_dumps(co: PyCodeRef, _vm: &VirtualMachine) -> PyBytes {
fn marshal_dumps(co: PyCodeRef) -> PyBytes {
PyBytes::new(co.code.to_bytes())
}

View File

@@ -25,7 +25,7 @@ use std::cmp::Ordering;
// Helper macro:
macro_rules! make_math_func {
( $fname:ident, $fun:ident ) => {
fn $fname(value: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn $fname(value: IntoPyFloat) -> f64 {
value.to_f64().$fun()
}
};
@@ -33,7 +33,7 @@ macro_rules! make_math_func {
macro_rules! make_math_func_bool {
( $fname:ident, $fun:ident ) => {
fn $fname(value: IntoPyFloat, _vm: &VirtualMachine) -> bool {
fn $fname(value: IntoPyFloat) -> bool {
value.to_f64().$fun()
}
};
@@ -98,7 +98,7 @@ fn math_isclose(args: IsCloseArgs, vm: &VirtualMachine) -> PyResult<bool> {
Ok((diff <= (rel_tol * b).abs()) || (diff <= (rel_tol * a).abs()) || (diff <= abs_tol))
}
fn math_copysign(a: IntoPyFloat, b: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_copysign(a: IntoPyFloat, b: IntoPyFloat) -> f64 {
let a = a.to_f64();
let b = b.to_f64();
if a.is_nan() || b.is_nan() {
@@ -112,18 +112,18 @@ fn math_copysign(a: IntoPyFloat, b: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
make_math_func!(math_exp, exp);
make_math_func!(math_expm1, exp_m1);
fn math_log(x: IntoPyFloat, base: OptionalArg<IntoPyFloat>, _vm: &VirtualMachine) -> f64 {
fn math_log(x: IntoPyFloat, base: OptionalArg<IntoPyFloat>) -> f64 {
base.map_or_else(|| x.to_f64().ln(), |base| x.to_f64().log(base.to_f64()))
}
fn math_log1p(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_log1p(x: IntoPyFloat) -> f64 {
(x.to_f64() + 1.0).ln()
}
make_math_func!(math_log2, log2);
make_math_func!(math_log10, log10);
fn math_pow(x: IntoPyFloat, y: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_pow(x: IntoPyFloat, y: IntoPyFloat) -> f64 {
x.to_f64().powf(y.to_f64())
}
@@ -134,24 +134,24 @@ make_math_func!(math_acos, acos);
make_math_func!(math_asin, asin);
make_math_func!(math_atan, atan);
fn math_atan2(y: IntoPyFloat, x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_atan2(y: IntoPyFloat, x: IntoPyFloat) -> f64 {
y.to_f64().atan2(x.to_f64())
}
make_math_func!(math_cos, cos);
fn math_hypot(x: IntoPyFloat, y: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_hypot(x: IntoPyFloat, y: IntoPyFloat) -> f64 {
x.to_f64().hypot(y.to_f64())
}
make_math_func!(math_sin, sin);
make_math_func!(math_tan, tan);
fn math_degrees(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_degrees(x: IntoPyFloat) -> f64 {
x.to_f64() * (180.0 / std::f64::consts::PI)
}
fn math_radians(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_radians(x: IntoPyFloat) -> f64 {
x.to_f64() * (std::f64::consts::PI / 180.0)
}
@@ -164,7 +164,7 @@ make_math_func!(math_sinh, sinh);
make_math_func!(math_tanh, tanh);
// Special functions:
fn math_erf(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_erf(x: IntoPyFloat) -> f64 {
let x = x.to_f64();
if x.is_nan() {
x
@@ -173,7 +173,7 @@ fn math_erf(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
}
}
fn math_erfc(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_erfc(x: IntoPyFloat) -> f64 {
let x = x.to_f64();
if x.is_nan() {
x
@@ -182,7 +182,7 @@ fn math_erfc(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
}
}
fn math_gamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_gamma(x: IntoPyFloat) -> f64 {
let x = x.to_f64();
if x.is_finite() {
gamma(x)
@@ -193,7 +193,7 @@ fn math_gamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
}
}
fn math_lgamma(x: IntoPyFloat, _vm: &VirtualMachine) -> f64 {
fn math_lgamma(x: IntoPyFloat) -> f64 {
let x = x.to_f64();
if x.is_finite() {
ln_gamma(x)
@@ -251,7 +251,7 @@ fn math_floor(value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
}
}
fn math_frexp(value: IntoPyFloat, _vm: &VirtualMachine) -> (f64, i32) {
fn math_frexp(value: IntoPyFloat) -> (f64, i32) {
let value = value.to_f64();
if value.is_finite() {
let (m, e) = objfloat::ufrexp(value);
@@ -261,11 +261,11 @@ fn math_frexp(value: IntoPyFloat, _vm: &VirtualMachine) -> (f64, i32) {
}
}
fn math_ldexp(value: PyFloatRef, i: PyIntRef, _vm: &VirtualMachine) -> f64 {
fn math_ldexp(value: PyFloatRef, i: PyIntRef) -> f64 {
value.to_f64() * (2_f64).powf(i.as_bigint().to_f64().unwrap())
}
fn math_gcd(a: PyIntRef, b: PyIntRef, _vm: &VirtualMachine) -> BigInt {
fn math_gcd(a: PyIntRef, b: PyIntRef) -> BigInt {
use num_integer::Integer;
a.as_bigint().gcd(b.as_bigint())
}
@@ -281,7 +281,7 @@ fn math_factorial(value: PyIntRef, vm: &VirtualMachine) -> PyResult<BigInt> {
Ok(ret)
}
fn math_modf(x: IntoPyFloat, _vm: &VirtualMachine) -> (f64, f64) {
fn math_modf(x: IntoPyFloat) -> (f64, f64) {
let x = x.to_f64();
if !x.is_finite() {
if x.is_infinite() {

View File

@@ -87,7 +87,7 @@ fn make_path(_vm: &VirtualMachine, path: PyStringRef, dir_fd: &DirFd) -> PyStrin
}
}
fn os_close(fileno: i64, _vm: &VirtualMachine) {
fn os_close(fileno: i64) {
//The File type automatically closes when it goes out of scope.
//To enable us to close these file descriptors (and hence prevent leaks)
//we seek to create the relevant File and simply let it pass out of scope!
@@ -519,11 +519,11 @@ struct FollowSymlinks {
}
impl DirEntryRef {
fn name(self, _vm: &VirtualMachine) -> String {
fn name(self) -> String {
self.entry.file_name().into_string().unwrap()
}
fn path(self, _vm: &VirtualMachine) -> String {
fn path(self) -> String {
self.entry.path().to_str().unwrap().to_owned()
}
@@ -568,7 +568,7 @@ impl DirEntryRef {
fn stat(self, dir_fd: DirFd, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult {
os_stat(
Either::A(self.path(vm).try_into_ref(vm)?),
Either::A(self.path().try_into_ref(vm)?),
dir_fd,
follow_symlinks,
vm,
@@ -610,23 +610,23 @@ impl ScandirIterator {
}
#[pymethod]
fn close(&self, _vm: &VirtualMachine) {
fn close(&self) {
self.exhausted.set(true);
}
#[pymethod(name = "__iter__")]
fn iter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn iter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
#[pymethod(name = "__enter__")]
fn enter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
fn enter(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}
#[pymethod(name = "__exit__")]
fn exit(zelf: PyRef<Self>, _args: PyFuncArgs, vm: &VirtualMachine) {
zelf.close(vm)
fn exit(zelf: PyRef<Self>, _args: PyFuncArgs) {
zelf.close()
}
}
@@ -814,7 +814,6 @@ fn os_stat(
_file: Either<PyStringRef, i64>,
_dir_fd: DirFd,
_follow_symlinks: FollowSymlinks,
_vm: &VirtualMachine,
) -> PyResult {
unimplemented!();
}
@@ -980,7 +979,7 @@ fn os_pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)>
}
#[cfg(unix)]
fn os_system(command: PyStringRef, _vm: &VirtualMachine) -> PyResult<i32> {
fn os_system(command: PyStringRef) -> PyResult<i32> {
use libc::system;
use std::ffi::CString;
@@ -1039,7 +1038,7 @@ fn os_cpu_count(vm: &VirtualMachine) -> PyObjectRef {
vm.new_int(cpu_count)
}
fn os_exit(code: i32, _vm: &VirtualMachine) {
fn os_exit(code: i32) {
std::process::exit(code)
}
@@ -1203,7 +1202,7 @@ macro_rules! suppress_iph {
}};
}
fn os_isatty(fd: i32, _vm: &VirtualMachine) -> bool {
fn os_isatty(fd: i32) -> bool {
unsafe { suppress_iph!(libc::isatty(fd)) != 0 }
}

View File

@@ -14,31 +14,31 @@ impl PyValue for Passwd {
type PasswdRef = PyRef<Passwd>;
impl PasswdRef {
fn pw_name(self, _vm: &VirtualMachine) -> String {
fn pw_name(self) -> String {
self.name.clone()
}
fn pw_passwd(self, _vm: &VirtualMachine) -> Option<String> {
fn pw_passwd(self) -> Option<String> {
self.passwd.clone()
}
fn pw_uid(self, _vm: &VirtualMachine) -> u32 {
fn pw_uid(self) -> u32 {
self.uid
}
fn pw_gid(self, _vm: &VirtualMachine) -> u32 {
fn pw_gid(self) -> u32 {
self.gid
}
fn pw_gecos(self, _vm: &VirtualMachine) -> Option<String> {
fn pw_gecos(self) -> Option<String> {
self.gecos.clone()
}
fn pw_dir(self, _vm: &VirtualMachine) -> String {
fn pw_dir(self) -> String {
self.dir.clone()
}
fn pw_shell(self, _vm: &VirtualMachine) -> String {
fn pw_shell(self) -> String {
self.shell.clone()
}
}

View File

@@ -312,7 +312,7 @@ fn re_compile(
make_regex(vm, pattern.as_str(), flags)
}
fn re_escape(pattern: PyStringRef, _vm: &VirtualMachine) -> String {
fn re_escape(pattern: PyStringRef) -> String {
regex::escape(pattern.as_str())
}

View File

@@ -81,7 +81,7 @@ fn getsignal(signalnum: i32, vm: &VirtualMachine) -> PyResult {
}
#[cfg(unix)]
fn alarm(time: u32, _vm: &VirtualMachine) -> u32 {
fn alarm(time: u32) -> u32 {
let prev_time = if time == 0 {
sig_alarm::cancel()
} else {

View File

@@ -231,12 +231,12 @@ impl PySocket {
}
#[pymethod]
fn close(&self, _vm: &VirtualMachine) {
fn close(&self) {
self.sock.replace(invalid_sock());
}
#[pymethod]
fn fileno(&self, _vm: &VirtualMachine) -> RawSocket {
fn fileno(&self) -> RawSocket {
sock_fileno(&self.sock())
}
@@ -361,15 +361,15 @@ impl PySocket {
}
#[pyproperty(name = "type")]
fn kind(&self, _vm: &VirtualMachine) -> i32 {
fn kind(&self) -> i32 {
self.kind.get()
}
#[pyproperty]
fn family(&self, _vm: &VirtualMachine) -> i32 {
fn family(&self) -> i32 {
self.family.get()
}
#[pyproperty]
fn proto(&self, _vm: &VirtualMachine) -> i32 {
fn proto(&self) -> i32 {
self.proto.get()
}
}
@@ -445,14 +445,6 @@ fn socket_inet_ntoa(packed_ip: PyBytesRef, vm: &VirtualMachine) -> PyResult {
Ok(vm.new_str(Ipv4Addr::from(ip_num).to_string()))
}
fn socket_hton<U: num_traits::int::PrimInt>(host: U, _vm: &VirtualMachine) -> U {
U::to_be(host)
}
fn socket_ntoh<U: num_traits::int::PrimInt>(network: U, _vm: &VirtualMachine) -> U {
U::from_be(network)
}
#[derive(FromArgs)]
struct GAIOptions {
#[pyarg(positional_only)]
@@ -618,10 +610,10 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"inet_aton" => ctx.new_function(socket_inet_aton),
"inet_ntoa" => ctx.new_function(socket_inet_ntoa),
"gethostname" => ctx.new_function(socket_gethostname),
"htonl" => ctx.new_function(socket_hton::<u32>),
"htons" => ctx.new_function(socket_hton::<u16>),
"ntohl" => ctx.new_function(socket_ntoh::<u32>),
"ntohs" => ctx.new_function(socket_ntoh::<u16>),
"htonl" => ctx.new_function(u32::to_be),
"htons" => ctx.new_function(u16::to_be),
"ntohl" => ctx.new_function(u32::from_be),
"ntohs" => ctx.new_function(u16::from_be),
"getdefaulttimeout" => ctx.new_function(|vm: &VirtualMachine| vm.get_none()),
"has_ipv6" => ctx.new_bool(false),
// constants

View File

@@ -134,11 +134,11 @@ impl PopenRef {
.into_ref_with_type(vm, cls)
}
fn poll(self, _vm: &VirtualMachine) -> Option<subprocess::ExitStatus> {
fn poll(self) -> Option<subprocess::ExitStatus> {
self.process.borrow_mut().poll()
}
fn return_code(self, _vm: &VirtualMachine) -> Option<subprocess::ExitStatus> {
fn return_code(self) -> Option<subprocess::ExitStatus> {
self.process.borrow().exit_status()
}
@@ -209,11 +209,11 @@ impl PopenRef {
})
}
fn pid(self, _vm: &VirtualMachine) -> Option<u32> {
fn pid(self) -> Option<u32> {
self.process.borrow().pid()
}
fn enter(self, _vm: &VirtualMachine) -> Self {
fn enter(self) -> Self {
self
}
@@ -222,7 +222,6 @@ impl PopenRef {
_exception_type: PyObjectRef,
_exception_value: PyObjectRef,
_traceback: PyObjectRef,
_vm: &VirtualMachine,
) {
let mut process = self.process.borrow_mut();
process.stdout.take();
@@ -230,7 +229,7 @@ impl PopenRef {
process.stderr.take();
}
fn args(self, _vm: &VirtualMachine) -> PyObjectRef {
fn args(self) -> PyObjectRef {
self.args.clone()
}
}

View File

@@ -87,17 +87,17 @@ impl PyValue for PySymbolTable {
#[pyimpl]
impl PySymbolTable {
#[pymethod(name = "get_name")]
fn get_name(&self, _vm: &VirtualMachine) -> String {
fn get_name(&self) -> String {
self.symtable.name.clone()
}
#[pymethod(name = "get_type")]
fn get_type(&self, _vm: &VirtualMachine) -> String {
fn get_type(&self) -> String {
self.symtable.typ.to_string()
}
#[pymethod(name = "get_lineno")]
fn get_lineno(&self, _vm: &VirtualMachine) -> usize {
fn get_lineno(&self) -> usize {
self.symtable.line_number
}
@@ -137,7 +137,7 @@ impl PySymbolTable {
}
#[pymethod(name = "has_children")]
fn has_children(&self, _vm: &VirtualMachine) -> bool {
fn has_children(&self) -> bool {
!self.symtable.sub_tables.is_empty()
}
@@ -173,42 +173,42 @@ impl PyValue for PySymbol {
#[pyimpl]
impl PySymbol {
#[pymethod(name = "get_name")]
fn get_name(&self, _vm: &VirtualMachine) -> String {
fn get_name(&self) -> String {
self.symbol.name.clone()
}
#[pymethod(name = "is_global")]
fn is_global(&self, _vm: &VirtualMachine) -> bool {
fn is_global(&self) -> bool {
self.symbol.is_global()
}
#[pymethod(name = "is_local")]
fn is_local(&self, _vm: &VirtualMachine) -> bool {
fn is_local(&self) -> bool {
self.symbol.is_local()
}
#[pymethod(name = "is_referenced")]
fn is_referenced(&self, _vm: &VirtualMachine) -> bool {
fn is_referenced(&self) -> bool {
self.symbol.is_referenced
}
#[pymethod(name = "is_assigned")]
fn is_assigned(&self, _vm: &VirtualMachine) -> bool {
fn is_assigned(&self) -> bool {
self.symbol.is_assigned
}
#[pymethod(name = "is_parameter")]
fn is_parameter(&self, _vm: &VirtualMachine) -> bool {
fn is_parameter(&self) -> bool {
self.symbol.is_parameter
}
#[pymethod(name = "is_free")]
fn is_free(&self, _vm: &VirtualMachine) -> bool {
fn is_free(&self) -> bool {
self.symbol.is_free
}
#[pymethod(name = "is_namespace")]
fn is_namespace(&self, _vm: &VirtualMachine) -> bool {
fn is_namespace(&self) -> bool {
// TODO
false
}

View File

@@ -16,7 +16,7 @@ fn rlock_acquire(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
Ok(vm.get_none())
}
fn rlock_release(_zelf: PyObjectRef, _vm: &VirtualMachine) {}
fn rlock_release(_zelf: PyObjectRef) {}
fn rlock_enter(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(instance, None)]);

View File

@@ -33,7 +33,7 @@ fn time_sleep(dur: Duration, vm: &VirtualMachine) -> PyResult<()> {
}
#[cfg(not(unix))]
fn time_sleep(dur: Duration, _vm: &VirtualMachine) {
fn time_sleep(dur: Duration) {
std::thread::sleep(dur);
}
@@ -125,7 +125,7 @@ fn time_asctime(t: OptionalArg<PyStructTime>, vm: &VirtualMachine) -> PyResult {
Ok(vm.ctx.new_str(formatted_time))
}
fn time_ctime(secs: OptionalArg<Either<f64, i64>>, _vm: &VirtualMachine) -> String {
fn time_ctime(secs: OptionalArg<Either<f64, i64>>) -> String {
let instant = optional_or_localtime(secs);
instant.format(&CFMT).to_string()
}

View File

@@ -165,7 +165,7 @@ impl PyUCD {
}
#[pyproperty]
fn unidata_version(&self, _vm: &VirtualMachine) -> String {
fn unidata_version(&self) -> String {
self.unic_version.to_string()
}
}

View File

@@ -9,7 +9,7 @@ use crate::pyobject::PyObjectRef;
use crate::vm::VirtualMachine;
use std::rc::Rc;
fn weakref_getweakrefcount(obj: PyObjectRef, _vm: &VirtualMachine) -> usize {
fn weakref_getweakrefcount(obj: PyObjectRef) -> usize {
Rc::weak_count(&obj)
}
@@ -18,7 +18,7 @@ fn weakref_getweakrefs(_obj: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
vm.ctx.new_list(vec![])
}
fn weakref_remove_dead_weakref(_obj: PyObjectRef, _key: PyObjectRef, _vm: &VirtualMachine) {
fn weakref_remove_dead_weakref(_obj: PyObjectRef, _key: PyObjectRef) {
// TODO
}

View File

@@ -97,11 +97,11 @@ impl SysFlags {
}
}
fn sys_getrefcount(obj: PyObjectRef, _vm: &VirtualMachine) -> usize {
fn sys_getrefcount(obj: PyObjectRef) -> usize {
Rc::strong_count(&obj)
}
fn sys_getsizeof(obj: PyObjectRef, _vm: &VirtualMachine) -> usize {
fn sys_getsizeof(obj: PyObjectRef) -> usize {
// TODO: implement default optional argument.
mem::size_of_val(&obj)
}
@@ -170,7 +170,7 @@ fn sys_setrecursionlimit(recursion_limit: usize, vm: &VirtualMachine) -> PyResul
}
// TODO implement string interning, this will be key for performance
fn sys_intern(value: PyStringRef, _vm: &VirtualMachine) -> PyStringRef {
fn sys_intern(value: PyStringRef) -> PyStringRef {
value
}

View File

@@ -1220,7 +1220,7 @@ impl VirtualMachine {
pub fn _hash(&self, obj: &PyObjectRef) -> PyResult<pyhash::PyHash> {
let hash_obj = self.call_method(obj, "__hash__", vec![])?;
if let Some(hash_value) = hash_obj.payload_if_subclass::<PyInt>(self) {
Ok(hash_value.hash(self))
Ok(hash_value.hash())
} else {
Err(self.new_type_error("__hash__ method should return an integer".to_owned()))
}

View File

@@ -72,22 +72,22 @@ impl PyJsValue {
}
#[pymethod]
fn null(&self, _vm: &VirtualMachine) -> PyJsValue {
fn null(&self) -> PyJsValue {
PyJsValue::new(JsValue::NULL)
}
#[pymethod]
fn undefined(&self, _vm: &VirtualMachine) -> PyJsValue {
fn undefined(&self) -> PyJsValue {
PyJsValue::new(JsValue::UNDEFINED)
}
#[pymethod]
fn new_from_str(&self, s: PyStringRef, _vm: &VirtualMachine) -> PyJsValue {
fn new_from_str(&self, s: PyStringRef) -> PyJsValue {
PyJsValue::new(s.as_str())
}
#[pymethod]
fn new_from_float(&self, n: PyFloatRef, _vm: &VirtualMachine) -> PyJsValue {
fn new_from_float(&self, n: PyFloatRef) -> PyJsValue {
PyJsValue::new(n.to_f64())
}
@@ -185,29 +185,29 @@ impl PyJsValue {
}
#[pymethod]
fn as_str(&self, _vm: &VirtualMachine) -> Option<String> {
fn as_str(&self) -> Option<String> {
self.value.as_string()
}
#[pymethod]
fn as_float(&self, _vm: &VirtualMachine) -> Option<f64> {
fn as_float(&self) -> Option<f64> {
self.value.as_f64()
}
#[pymethod]
fn as_bool(&self, _vm: &VirtualMachine) -> Option<bool> {
fn as_bool(&self) -> Option<bool> {
self.value.as_bool()
}
#[pymethod(name = "typeof")]
fn type_of(&self, _vm: &VirtualMachine) -> String {
fn type_of(&self) -> String {
type_of(&self.value)
}
#[pymethod]
/// Checks that `typeof self == "object" && self !== null`. Use instead
/// of `value.typeof() == "object"`
fn is_object(&self, _vm: &VirtualMachine) -> bool {
fn is_object(&self) -> bool {
self.value.is_object()
}
@@ -217,7 +217,7 @@ impl PyJsValue {
}
#[pymethod(name = "__repr__")]
fn repr(&self, _vm: &VirtualMachine) -> String {
fn repr(&self) -> String {
format!("{:?}", self.value)
}
}