From 32adc327b6b1e28c4e2dfe2862714e7829f07d98 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 12 Aug 2021 06:51:28 +0900 Subject: [PATCH] clean up pymethod with names --- vm/src/builtins/bytearray.rs | 84 ++++++++++++++++++------------------ vm/src/builtins/bytes.rs | 78 ++++++++++++++++----------------- vm/src/builtins/complex.rs | 2 +- vm/src/builtins/float.rs | 2 +- vm/src/builtins/range.rs | 4 +- vm/src/builtins/slice.rs | 2 +- vm/src/builtins/tuple.rs | 4 +- vm/src/stdlib/hashlib.rs | 6 +-- vm/src/stdlib/re.rs | 6 +-- vm/src/stdlib/symtable.rs | 2 +- 10 files changed, 95 insertions(+), 95 deletions(-) diff --git a/vm/src/builtins/bytearray.rs b/vm/src/builtins/bytearray.rs index 32998c895..f6c821085 100644 --- a/vm/src/builtins/bytearray.rs +++ b/vm/src/builtins/bytearray.rs @@ -305,67 +305,67 @@ impl PyByteArray { Ok(()) } - #[pymethod(name = "isalnum")] + #[pymethod] fn isalnum(&self) -> bool { self.inner().isalnum() } - #[pymethod(name = "isalpha")] + #[pymethod] fn isalpha(&self) -> bool { self.inner().isalpha() } - #[pymethod(name = "isascii")] + #[pymethod] fn isascii(&self) -> bool { self.inner().isascii() } - #[pymethod(name = "isdigit")] + #[pymethod] fn isdigit(&self) -> bool { self.inner().isdigit() } - #[pymethod(name = "islower")] + #[pymethod] fn islower(&self) -> bool { self.inner().islower() } - #[pymethod(name = "isspace")] + #[pymethod] fn isspace(&self) -> bool { self.inner().isspace() } - #[pymethod(name = "isupper")] + #[pymethod] fn isupper(&self) -> bool { self.inner().isupper() } - #[pymethod(name = "istitle")] + #[pymethod] fn istitle(&self) -> bool { self.inner().istitle() } - #[pymethod(name = "lower")] + #[pymethod] fn lower(&self) -> Self { self.inner().lower().into() } - #[pymethod(name = "upper")] + #[pymethod] fn upper(&self) -> Self { self.inner().upper().into() } - #[pymethod(name = "capitalize")] + #[pymethod] fn capitalize(&self) -> Self { self.inner().capitalize().into() } - #[pymethod(name = "swapcase")] + #[pymethod] fn swapcase(&self) -> Self { self.inner().swapcase().into() } - #[pymethod(name = "hex")] + #[pymethod] fn hex( &self, sep: OptionalArg>, @@ -380,7 +380,7 @@ impl PyByteArray { Ok(PyBytesInner::fromhex(string.as_str(), vm)?.into()) } - #[pymethod(name = "center")] + #[pymethod] fn center( &self, options: ByteInnerPaddingOptions, @@ -389,7 +389,7 @@ impl PyByteArray { Ok(self.inner().center(options, vm)?.into()) } - #[pymethod(name = "ljust")] + #[pymethod] fn ljust( &self, options: ByteInnerPaddingOptions, @@ -398,7 +398,7 @@ impl PyByteArray { Ok(self.inner().ljust(options, vm)?.into()) } - #[pymethod(name = "rjust")] + #[pymethod] fn rjust( &self, options: ByteInnerPaddingOptions, @@ -407,17 +407,17 @@ impl PyByteArray { Ok(self.inner().rjust(options, vm)?.into()) } - #[pymethod(name = "count")] + #[pymethod] fn count(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { self.inner().count(options, vm) } - #[pymethod(name = "join")] + #[pymethod] fn join(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult { Ok(self.inner().join(iter, vm)?.into()) } - #[pymethod(name = "endswith")] + #[pymethod] fn endswith(&self, options: anystr::StartsEndsWithArgs, vm: &VirtualMachine) -> PyResult { self.borrow_buf().py_startsendswith( options, @@ -428,7 +428,7 @@ impl PyByteArray { ) } - #[pymethod(name = "startswith")] + #[pymethod] fn startswith( &self, options: anystr::StartsEndsWithArgs, @@ -443,31 +443,31 @@ impl PyByteArray { ) } - #[pymethod(name = "find")] + #[pymethod] fn find(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner().find(options, |h, n| h.find(n), vm)?; Ok(index.map_or(-1, |v| v as isize)) } - #[pymethod(name = "index")] + #[pymethod] fn index(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner().find(options, |h, n| h.find(n), vm)?; index.ok_or_else(|| vm.new_value_error("substring not found".to_owned())) } - #[pymethod(name = "rfind")] + #[pymethod] fn rfind(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner().find(options, |h, n| h.rfind(n), vm)?; Ok(index.map_or(-1, |v| v as isize)) } - #[pymethod(name = "rindex")] + #[pymethod] fn rindex(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner().find(options, |h, n| h.rfind(n), vm)?; index.ok_or_else(|| vm.new_value_error("substring not found".to_owned())) } - #[pymethod(name = "translate")] + #[pymethod] fn translate( &self, options: ByteInnerTranslateOptions, @@ -476,17 +476,17 @@ impl PyByteArray { Ok(self.inner().translate(options, vm)?.into()) } - #[pymethod(name = "strip")] + #[pymethod] fn strip(&self, chars: OptionalOption) -> Self { self.inner().strip(chars).into() } - #[pymethod(name = "lstrip")] + #[pymethod] fn lstrip(&self, chars: OptionalOption) -> Self { self.inner().lstrip(chars).into() } - #[pymethod(name = "rstrip")] + #[pymethod] fn rstrip(&self, chars: OptionalOption) -> Self { self.inner().rstrip(chars).into() } @@ -498,7 +498,7 @@ impl PyByteArray { /// /// If the bytearray starts with the prefix string, return string[len(prefix):] /// Otherwise, return a copy of the original bytearray. - #[pymethod(name = "removeprefix")] + #[pymethod] fn removeprefix(&self, prefix: PyBytesInner) -> Self { self.inner().removeprefix(prefix).into() } @@ -510,24 +510,24 @@ impl PyByteArray { /// /// If the bytearray ends with the suffix string, return string[:len(suffix)] /// Otherwise, return a copy of the original bytearray. - #[pymethod(name = "removesuffix")] + #[pymethod] fn removesuffix(&self, suffix: PyBytesInner) -> Self { self.inner().removesuffix(suffix).to_vec().into() } - #[pymethod(name = "split")] + #[pymethod] fn split(&self, options: ByteInnerSplitOptions, vm: &VirtualMachine) -> PyResult { self.inner() .split(options, |s, vm| vm.ctx.new_bytearray(s.to_vec()), vm) } - #[pymethod(name = "rsplit")] + #[pymethod] fn rsplit(&self, options: ByteInnerSplitOptions, vm: &VirtualMachine) -> PyResult { self.inner() .rsplit(options, |s, vm| vm.ctx.new_bytearray(s.to_vec()), vm) } - #[pymethod(name = "partition")] + #[pymethod] fn partition(&self, sep: PyBytesInner, vm: &VirtualMachine) -> PyResult { // sep ALWAYS converted to bytearray even it's bytes or memoryview // so its ok to accept PyBytesInner @@ -541,7 +541,7 @@ impl PyByteArray { ])) } - #[pymethod(name = "rpartition")] + #[pymethod] fn rpartition(&self, sep: PyBytesInner, vm: &VirtualMachine) -> PyResult { let value = self.inner(); let (back, has_mid, front) = value.rpartition(&sep, vm)?; @@ -553,12 +553,12 @@ impl PyByteArray { ])) } - #[pymethod(name = "expandtabs")] + #[pymethod] fn expandtabs(&self, options: anystr::ExpandTabsArgs) -> Self { self.inner().expandtabs(options).into() } - #[pymethod(name = "splitlines")] + #[pymethod] fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef { let lines = self .inner() @@ -566,12 +566,12 @@ impl PyByteArray { vm.ctx.new_list(lines) } - #[pymethod(name = "zfill")] + #[pymethod] fn zfill(&self, width: isize) -> Self { self.inner().zfill(width).into() } - #[pymethod(name = "replace")] + #[pymethod] fn replace( &self, old: PyBytesInner, @@ -582,18 +582,18 @@ impl PyByteArray { Ok(self.inner().replace(old, new, count, vm)?.into()) } - #[pymethod(name = "clear")] + #[pymethod] fn clear(zelf: PyRef, vm: &VirtualMachine) -> PyResult<()> { zelf.try_resizable(vm)?.elements.clear(); Ok(()) } - #[pymethod(name = "copy")] + #[pymethod] fn copy(&self) -> Self { self.borrow_buf().to_vec().into() } - #[pymethod(name = "title")] + #[pymethod] fn title(&self) -> Self { self.inner().title().into() } @@ -620,7 +620,7 @@ impl PyByteArray { vm.ctx.not_implemented() } - #[pymethod(name = "reverse")] + #[pymethod] fn reverse(&self) { self.borrow_buf_mut().reverse(); } diff --git a/vm/src/builtins/bytes.rs b/vm/src/builtins/bytes.rs index da79a0626..1bd61fed3 100644 --- a/vm/src/builtins/bytes.rs +++ b/vm/src/builtins/bytes.rs @@ -154,67 +154,67 @@ impl PyBytes { self.inner.getitem("byte", needle, vm) // byte != Self::NAME } - #[pymethod(name = "isalnum")] + #[pymethod] fn isalnum(&self) -> bool { self.inner.isalnum() } - #[pymethod(name = "isalpha")] + #[pymethod] fn isalpha(&self) -> bool { self.inner.isalpha() } - #[pymethod(name = "isascii")] + #[pymethod] fn isascii(&self) -> bool { self.inner.isascii() } - #[pymethod(name = "isdigit")] + #[pymethod] fn isdigit(&self) -> bool { self.inner.isdigit() } - #[pymethod(name = "islower")] + #[pymethod] fn islower(&self) -> bool { self.inner.islower() } - #[pymethod(name = "isspace")] + #[pymethod] fn isspace(&self) -> bool { self.inner.isspace() } - #[pymethod(name = "isupper")] + #[pymethod] fn isupper(&self) -> bool { self.inner.isupper() } - #[pymethod(name = "istitle")] + #[pymethod] fn istitle(&self) -> bool { self.inner.istitle() } - #[pymethod(name = "lower")] + #[pymethod] fn lower(&self) -> Self { self.inner.lower().into() } - #[pymethod(name = "upper")] + #[pymethod] fn upper(&self) -> Self { self.inner.upper().into() } - #[pymethod(name = "capitalize")] + #[pymethod] fn capitalize(&self) -> Self { self.inner.capitalize().into() } - #[pymethod(name = "swapcase")] + #[pymethod] fn swapcase(&self) -> Self { self.inner.swapcase().into() } - #[pymethod(name = "hex")] + #[pymethod] pub(crate) fn hex( &self, sep: OptionalArg>, @@ -229,32 +229,32 @@ impl PyBytes { Ok(PyBytesInner::fromhex(string.as_str(), vm)?.into()) } - #[pymethod(name = "center")] + #[pymethod] fn center(&self, options: ByteInnerPaddingOptions, vm: &VirtualMachine) -> PyResult { Ok(self.inner.center(options, vm)?.into()) } - #[pymethod(name = "ljust")] + #[pymethod] fn ljust(&self, options: ByteInnerPaddingOptions, vm: &VirtualMachine) -> PyResult { Ok(self.inner.ljust(options, vm)?.into()) } - #[pymethod(name = "rjust")] + #[pymethod] fn rjust(&self, options: ByteInnerPaddingOptions, vm: &VirtualMachine) -> PyResult { Ok(self.inner.rjust(options, vm)?.into()) } - #[pymethod(name = "count")] + #[pymethod] fn count(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { self.inner.count(options, vm) } - #[pymethod(name = "join")] + #[pymethod] fn join(&self, iter: PyIterable, vm: &VirtualMachine) -> PyResult { Ok(self.inner.join(iter, vm)?.into()) } - #[pymethod(name = "endswith")] + #[pymethod] fn endswith(&self, options: anystr::StartsEndsWithArgs, vm: &VirtualMachine) -> PyResult { self.inner.elements[..].py_startsendswith( options, @@ -265,7 +265,7 @@ impl PyBytes { ) } - #[pymethod(name = "startswith")] + #[pymethod] fn startswith( &self, options: anystr::StartsEndsWithArgs, @@ -280,31 +280,31 @@ impl PyBytes { ) } - #[pymethod(name = "find")] + #[pymethod] fn find(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner.find(options, |h, n| h.find(n), vm)?; Ok(index.map_or(-1, |v| v as isize)) } - #[pymethod(name = "index")] + #[pymethod] fn index(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner.find(options, |h, n| h.find(n), vm)?; index.ok_or_else(|| vm.new_value_error("substring not found".to_owned())) } - #[pymethod(name = "rfind")] + #[pymethod] fn rfind(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner.find(options, |h, n| h.rfind(n), vm)?; Ok(index.map_or(-1, |v| v as isize)) } - #[pymethod(name = "rindex")] + #[pymethod] fn rindex(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult { let index = self.inner.find(options, |h, n| h.rfind(n), vm)?; index.ok_or_else(|| vm.new_value_error("substring not found".to_owned())) } - #[pymethod(name = "translate")] + #[pymethod] fn translate( &self, options: ByteInnerTranslateOptions, @@ -313,17 +313,17 @@ impl PyBytes { Ok(self.inner.translate(options, vm)?.into()) } - #[pymethod(name = "strip")] + #[pymethod] fn strip(&self, chars: OptionalOption) -> Self { self.inner.strip(chars).into() } - #[pymethod(name = "lstrip")] + #[pymethod] fn lstrip(&self, chars: OptionalOption) -> Self { self.inner.lstrip(chars).into() } - #[pymethod(name = "rstrip")] + #[pymethod] fn rstrip(&self, chars: OptionalOption) -> Self { self.inner.rstrip(chars).into() } @@ -335,7 +335,7 @@ impl PyBytes { /// /// If the bytes starts with the prefix string, return string[len(prefix):] /// Otherwise, return a copy of the original bytes. - #[pymethod(name = "removeprefix")] + #[pymethod] fn removeprefix(&self, prefix: PyBytesInner) -> Self { self.inner.removeprefix(prefix).into() } @@ -347,24 +347,24 @@ impl PyBytes { /// /// If the bytes ends with the suffix string, return string[:len(suffix)] /// Otherwise, return a copy of the original bytes. - #[pymethod(name = "removesuffix")] + #[pymethod] fn removesuffix(&self, suffix: PyBytesInner) -> Self { self.inner.removesuffix(suffix).into() } - #[pymethod(name = "split")] + #[pymethod] fn split(&self, options: ByteInnerSplitOptions, vm: &VirtualMachine) -> PyResult { self.inner .split(options, |s, vm| vm.ctx.new_bytes(s.to_vec()), vm) } - #[pymethod(name = "rsplit")] + #[pymethod] fn rsplit(&self, options: ByteInnerSplitOptions, vm: &VirtualMachine) -> PyResult { self.inner .rsplit(options, |s, vm| vm.ctx.new_bytes(s.to_vec()), vm) } - #[pymethod(name = "partition")] + #[pymethod] fn partition(&self, sep: PyObjectRef, vm: &VirtualMachine) -> PyResult { let sub = PyBytesInner::try_from_object(vm, sep.clone())?; let (front, has_mid, back) = self.inner.partition(&sub, vm)?; @@ -379,7 +379,7 @@ impl PyBytes { ])) } - #[pymethod(name = "rpartition")] + #[pymethod] fn rpartition(&self, sep: PyObjectRef, vm: &VirtualMachine) -> PyResult { let sub = PyBytesInner::try_from_object(vm, sep.clone())?; let (back, has_mid, front) = self.inner.rpartition(&sub, vm)?; @@ -394,12 +394,12 @@ impl PyBytes { ])) } - #[pymethod(name = "expandtabs")] + #[pymethod] fn expandtabs(&self, options: anystr::ExpandTabsArgs) -> Self { self.inner.expandtabs(options).into() } - #[pymethod(name = "splitlines")] + #[pymethod] fn splitlines(&self, options: anystr::SplitLinesArgs, vm: &VirtualMachine) -> PyObjectRef { let lines = self .inner @@ -407,12 +407,12 @@ impl PyBytes { vm.ctx.new_list(lines) } - #[pymethod(name = "zfill")] + #[pymethod] fn zfill(&self, width: isize) -> Self { self.inner.zfill(width).into() } - #[pymethod(name = "replace")] + #[pymethod] fn replace( &self, old: PyBytesInner, @@ -423,7 +423,7 @@ impl PyBytes { Ok(self.inner.replace(old, new, count, vm)?.into()) } - #[pymethod(name = "title")] + #[pymethod] fn title(&self) -> Self { self.inner.title().into() } diff --git a/vm/src/builtins/complex.rs b/vm/src/builtins/complex.rs index 42e0c209e..d58bc0f4e 100644 --- a/vm/src/builtins/complex.rs +++ b/vm/src/builtins/complex.rs @@ -149,7 +149,7 @@ impl PyComplex { self.op(other, |a, b| Ok(b - a), vm) } - #[pymethod(name = "conjugate")] + #[pymethod] fn conjugate(&self) -> Complex64 { self.value.conj() } diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index e6b054ddf..da2c28f5d 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -449,7 +449,7 @@ impl PyFloat { 0.0f64 } - #[pymethod(name = "conjugate")] + #[pymethod] fn conjugate(zelf: PyRef) -> PyRef { zelf } diff --git a/vm/src/builtins/range.rs b/vm/src/builtins/range.rs index 8edd01091..ab1105047 100644 --- a/vm/src/builtins/range.rs +++ b/vm/src/builtins/range.rs @@ -301,7 +301,7 @@ impl PyRange { (vm.ctx.types.range_type.clone(), range_paramters_tuple) } - #[pymethod(name = "index")] + #[pymethod] fn index(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult { if let Ok(int) = needle.clone().downcast::() { match self.index_of(int.as_bigint()) { @@ -318,7 +318,7 @@ impl PyRange { } } - #[pymethod(name = "count")] + #[pymethod] fn count(&self, item: PyObjectRef, vm: &VirtualMachine) -> PyResult { if let Ok(int) = item.clone().downcast::() { if self.index_of(int.as_bigint()).is_some() { diff --git a/vm/src/builtins/slice.rs b/vm/src/builtins/slice.rs index 3bdbefeee..4e88061bb 100644 --- a/vm/src/builtins/slice.rs +++ b/vm/src/builtins/slice.rs @@ -204,7 +204,7 @@ impl PySlice { Ok((start, stop, step)) } - #[pymethod(name = "indices")] + #[pymethod] fn indices(&self, length: PyIntRef, vm: &VirtualMachine) -> PyResult { let length = length.as_bigint(); if length.is_negative() { diff --git a/vm/src/builtins/tuple.rs b/vm/src/builtins/tuple.rs index 77de4def5..a5b5119f5 100644 --- a/vm/src/builtins/tuple.rs +++ b/vm/src/builtins/tuple.rs @@ -125,7 +125,7 @@ impl PyTuple { !self.elements.is_empty() } - #[pymethod(name = "count")] + #[pymethod] fn count(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult { let mut count: usize = 0; for element in self.elements.iter() { @@ -196,7 +196,7 @@ impl PyTuple { Ok(result) } - #[pymethod(name = "index")] + #[pymethod] fn index( &self, needle: PyObjectRef, diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index 018988950..06d3919c1 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -70,17 +70,17 @@ mod hashlib { Ok(vm.ctx.new_int(self.read().digest_size())) } - #[pymethod(name = "update")] + #[pymethod] fn update(&self, data: PyBytesRef) { self.write().input(data.as_bytes()); } - #[pymethod(name = "digest")] + #[pymethod] fn digest(&self) -> PyBytes { self.get_digest().into() } - #[pymethod(name = "hexdigest")] + #[pymethod] fn hexdigest(&self) -> String { let result = self.get_digest(); hex::encode(result) diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 4849839f8..442f5ed71 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -313,12 +313,12 @@ impl PyPattern { do_match(self, text) } - #[pymethod(name = "search")] + #[pymethod] fn search(&self, text: PyStrRef) -> Option { do_search(self, text) } - #[pymethod(name = "sub")] + #[pymethod] fn sub(&self, repl: PyStrRef, text: PyStrRef, vm: &VirtualMachine) -> PyResult { let replaced_text = self .regex @@ -327,7 +327,7 @@ impl PyPattern { Ok(vm.ctx.new_str(replaced_text)) } - #[pymethod(name = "subn")] + #[pymethod] fn subn(&self, repl: PyStrRef, text: PyStrRef, vm: &VirtualMachine) -> PyResult { self.sub(repl, text, vm) } diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 6f72f08d3..dbcbf1b3d 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -83,7 +83,7 @@ mod decl { self.symtable.typ == SymbolTableType::Function } - #[pymethod(name = "lookup")] + #[pymethod] fn lookup(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult { let name = name.as_str(); if let Some(symbol) = self.symtable.symbols.get(name) {