Merge pull request #2863 from youknowone/funcnames

clean up pymethod with names
This commit is contained in:
Jim Fasarakis-Hilliard
2021-08-12 18:19:34 +03:00
committed by GitHub
10 changed files with 95 additions and 95 deletions

View File

@@ -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<Either<PyStrRef, PyBytesRef>>,
@@ -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<usize> {
self.inner().count(options, vm)
}
#[pymethod(name = "join")]
#[pymethod]
fn join(&self, iter: PyIterable<PyBytesInner>, vm: &VirtualMachine) -> PyResult<PyByteArray> {
Ok(self.inner().join(iter, vm)?.into())
}
#[pymethod(name = "endswith")]
#[pymethod]
fn endswith(&self, options: anystr::StartsEndsWithArgs, vm: &VirtualMachine) -> PyResult<bool> {
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<isize> {
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<usize> {
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<isize> {
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<usize> {
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<PyBytesInner>) -> Self {
self.inner().strip(chars).into()
}
#[pymethod(name = "lstrip")]
#[pymethod]
fn lstrip(&self, chars: OptionalOption<PyBytesInner>) -> Self {
self.inner().lstrip(chars).into()
}
#[pymethod(name = "rstrip")]
#[pymethod]
fn rstrip(&self, chars: OptionalOption<PyBytesInner>) -> 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<Self>, 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();
}

View File

@@ -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<Either<PyStrRef, PyBytesRef>>,
@@ -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<PyBytes> {
Ok(self.inner.center(options, vm)?.into())
}
#[pymethod(name = "ljust")]
#[pymethod]
fn ljust(&self, options: ByteInnerPaddingOptions, vm: &VirtualMachine) -> PyResult<PyBytes> {
Ok(self.inner.ljust(options, vm)?.into())
}
#[pymethod(name = "rjust")]
#[pymethod]
fn rjust(&self, options: ByteInnerPaddingOptions, vm: &VirtualMachine) -> PyResult<PyBytes> {
Ok(self.inner.rjust(options, vm)?.into())
}
#[pymethod(name = "count")]
#[pymethod]
fn count(&self, options: ByteInnerFindOptions, vm: &VirtualMachine) -> PyResult<usize> {
self.inner.count(options, vm)
}
#[pymethod(name = "join")]
#[pymethod]
fn join(&self, iter: PyIterable<PyBytesInner>, vm: &VirtualMachine) -> PyResult<PyBytes> {
Ok(self.inner.join(iter, vm)?.into())
}
#[pymethod(name = "endswith")]
#[pymethod]
fn endswith(&self, options: anystr::StartsEndsWithArgs, vm: &VirtualMachine) -> PyResult<bool> {
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<isize> {
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<usize> {
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<isize> {
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<usize> {
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<PyBytesInner>) -> Self {
self.inner.strip(chars).into()
}
#[pymethod(name = "lstrip")]
#[pymethod]
fn lstrip(&self, chars: OptionalOption<PyBytesInner>) -> Self {
self.inner.lstrip(chars).into()
}
#[pymethod(name = "rstrip")]
#[pymethod]
fn rstrip(&self, chars: OptionalOption<PyBytesInner>) -> 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()
}

View File

@@ -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()
}

View File

@@ -449,7 +449,7 @@ impl PyFloat {
0.0f64
}
#[pymethod(name = "conjugate")]
#[pymethod]
fn conjugate(zelf: PyRef<Self>) -> PyRef<Self> {
zelf
}

View File

@@ -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<BigInt> {
if let Ok(int) = needle.clone().downcast::<PyInt>() {
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<usize> {
if let Ok(int) = item.clone().downcast::<PyInt>() {
if self.index_of(int.as_bigint()).is_some() {

View File

@@ -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() {

View File

@@ -125,7 +125,7 @@ impl PyTuple {
!self.elements.is_empty()
}
#[pymethod(name = "count")]
#[pymethod]
fn count(&self, needle: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
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,

View File

@@ -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)

View File

@@ -313,12 +313,12 @@ impl PyPattern {
do_match(self, text)
}
#[pymethod(name = "search")]
#[pymethod]
fn search(&self, text: PyStrRef) -> Option<PyMatch> {
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)
}

View File

@@ -83,7 +83,7 @@ mod decl {
self.symtable.typ == SymbolTableType::Function
}
#[pymethod(name = "lookup")]
#[pymethod]
fn lookup(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult<PySymbolRef> {
let name = name.as_str();
if let Some(symbol) = self.symtable.symbols.get(name) {