From f81ad04ce3d59f0a02bc3780d885e51ccc695b05 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sat, 26 Sep 2020 00:20:02 +0900 Subject: [PATCH] PyString -> PyStr --- src/shell/helper.rs | 9 +-- vm/src/builtins.rs | 48 ++++++----- vm/src/bytesinner.rs | 16 ++-- vm/src/dictdatatype.rs | 10 +-- vm/src/exceptions.rs | 18 ++--- vm/src/frame.rs | 43 +++++----- vm/src/function.rs | 2 +- vm/src/obj/objbool.rs | 8 +- vm/src/obj/objbuiltinfunc.rs | 16 ++-- vm/src/obj/objbytearray.rs | 6 +- vm/src/obj/objbytes.rs | 6 +- vm/src/obj/objcomplex.rs | 4 +- vm/src/obj/objcoroutine.rs | 4 +- vm/src/obj/objdict.rs | 2 +- vm/src/obj/objfloat.rs | 8 +- vm/src/obj/objframe.rs | 4 +- vm/src/obj/objfunction.rs | 4 +- vm/src/obj/objint.rs | 12 +-- vm/src/obj/objmappingproxy.rs | 6 +- vm/src/obj/objmodule.rs | 15 ++-- vm/src/obj/objobject.rs | 16 ++-- vm/src/obj/objstr.rs | 142 ++++++++++++++++----------------- vm/src/obj/objsuper.rs | 4 +- vm/src/obj/objtype.rs | 14 ++-- vm/src/py_io.rs | 4 +- vm/src/pyobject.rs | 10 +-- vm/src/stdlib/array.rs | 4 +- vm/src/stdlib/binascii.rs | 6 +- vm/src/stdlib/csv.rs | 4 +- vm/src/stdlib/dis.rs | 4 +- vm/src/stdlib/hashlib.rs | 4 +- vm/src/stdlib/imp.rs | 14 ++-- vm/src/stdlib/io.rs | 32 ++++---- vm/src/stdlib/json.rs | 17 ++-- vm/src/stdlib/keyword.rs | 4 +- vm/src/stdlib/msvcrt.rs | 4 +- vm/src/stdlib/operator.rs | 6 +- vm/src/stdlib/os.rs | 24 +++--- vm/src/stdlib/pwd.rs | 4 +- vm/src/stdlib/pystruct.rs | 24 +++--- vm/src/stdlib/re.rs | 61 +++++++------- vm/src/stdlib/socket.rs | 26 +++--- vm/src/stdlib/ssl.rs | 16 ++-- vm/src/stdlib/string.rs | 6 +- vm/src/stdlib/symtable.rs | 10 +-- vm/src/stdlib/thread.rs | 8 +- vm/src/stdlib/time_module.rs | 14 +--- vm/src/stdlib/tokenize.rs | 4 +- vm/src/stdlib/unicodedata.rs | 19 ++--- vm/src/stdlib/warnings.rs | 4 +- vm/src/stdlib/winapi.rs | 14 ++-- vm/src/stdlib/winreg.rs | 12 +-- vm/src/sysmodule.rs | 4 +- vm/src/types.rs | 2 +- vm/src/vm.rs | 32 ++++---- wasm/lib/src/browser_module.rs | 18 ++--- wasm/lib/src/js_module.rs | 8 +- wasm/lib/src/wasm_builtins.rs | 4 +- 58 files changed, 401 insertions(+), 443 deletions(-) diff --git a/src/shell/helper.rs b/src/shell/helper.rs index c1888bb44..284598c52 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -1,4 +1,4 @@ -use rustpython_vm::obj::objstr::PyStringRef; +use rustpython_vm::obj::objstr::PyStrRef; use rustpython_vm::pyobject::{BorrowValue, PyIterable, PyResult, TryFromObject}; use rustpython_vm::scope::{NameProtocol, Scope}; use rustpython_vm::VirtualMachine; @@ -59,16 +59,13 @@ impl<'vm> ShellHelper<'vm> { fn get_available_completions<'w>( &self, words: &'w [String], - ) -> Option<( - &'w str, - Box> + 'vm>, - )> { + ) -> Option<(&'w str, Box> + 'vm>)> { // the very first word and then all the ones after the dot let (first, rest) = words.split_first().unwrap(); let str_iter_method = |obj, name| { let iter = self.vm.call_method(obj, name, vec![])?; - PyIterable::::try_from_object(self.vm, iter)?.iter(self.vm) + PyIterable::::try_from_object(self.vm, iter)?.iter(self.vm) }; if let Some((last, parents)) = rest.split_last() { diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 8df09739b..f35dbdd4d 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -29,7 +29,7 @@ mod decl { use crate::obj::objiter; use crate::obj::objlist::{PyList, SortOptions}; use crate::obj::objsequence; - use crate::obj::objstr::{PyString, PyStringRef}; + use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtype::{self, PyClassRef}; use crate::pyobject::{ BorrowValue, Either, IdProtocol, ItemProtocol, PyCallable, PyIterable, PyObjectRef, @@ -108,11 +108,11 @@ mod decl { #[allow(dead_code)] struct CompileArgs { #[pyarg(positional_only, optional = false)] - source: Either, + source: Either, #[pyarg(positional_only, optional = false)] - filename: PyStringRef, + filename: PyStrRef, #[pyarg(positional_only, optional = false)] - mode: PyStringRef, + mode: PyStrRef, #[pyarg(positional_or_keyword, optional = true)] flags: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] @@ -162,7 +162,7 @@ mod decl { } #[pyfunction] - fn delattr(obj: PyObjectRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn delattr(obj: PyObjectRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { vm.del_attr(&obj, attr.into_object()) } @@ -200,7 +200,7 @@ mod decl { #[cfg(feature = "rustpython-compiler")] #[pyfunction] fn eval( - source: Either, + source: Either, scope: ScopeArgs, vm: &VirtualMachine, ) -> PyResult { @@ -212,7 +212,7 @@ mod decl { #[cfg(feature = "rustpython-compiler")] #[pyfunction] fn exec( - source: Either, + source: Either, scope: ScopeArgs, vm: &VirtualMachine, ) -> PyResult { @@ -222,7 +222,7 @@ mod decl { #[cfg(feature = "rustpython-compiler")] fn run_code( vm: &VirtualMachine, - source: Either, + source: Either, scope: ScopeArgs, mode: compile::Mode, ) -> PyResult { @@ -272,12 +272,12 @@ mod decl { #[pyfunction] fn format( value: PyObjectRef, - format_spec: OptionalArg, + format_spec: OptionalArg, vm: &VirtualMachine, - ) -> PyResult { + ) -> PyResult { let format_spec = format_spec .into_option() - .unwrap_or_else(|| PyString::from("").into_ref(vm)); + .unwrap_or_else(|| PyStr::from("").into_ref(vm)); vm.call_method(&value, "__format__", vec![format_spec.into_object()])? .downcast() @@ -304,7 +304,7 @@ mod decl { #[pyfunction] fn getattr( obj: PyObjectRef, - attr: PyStringRef, + attr: PyStrRef, default: OptionalArg, vm: &VirtualMachine, ) -> PyResult { @@ -322,7 +322,7 @@ mod decl { } #[pyfunction] - fn hasattr(obj: PyObjectRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn hasattr(obj: PyObjectRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Err(ex) = vm.get_attribute(obj, attr) { catch_attr_exception(ex, false, vm) } else { @@ -355,7 +355,7 @@ mod decl { } #[pyfunction] - fn input(prompt: OptionalArg, vm: &VirtualMachine) -> PyResult { + fn input(prompt: OptionalArg, vm: &VirtualMachine) -> PyResult { let stdin = sysmodule::get_stdin(vm)?; let stdout = sysmodule::get_stdout(vm)?; let stderr = sysmodule::get_stderr(vm)?; @@ -590,7 +590,7 @@ mod decl { } #[pyfunction] - fn ord(string: Either, vm: &VirtualMachine) -> PyResult { + fn ord(string: Either, vm: &VirtualMachine) -> PyResult { match string { Either::A(bytes) => bytes.with_ref(|bytes| { let bytes_len = bytes.len(); @@ -670,9 +670,9 @@ mod decl { #[derive(Debug, Default, FromArgs)] pub struct PrintOptions { #[pyarg(keyword_only, default = "None")] - sep: Option, + sep: Option, #[pyarg(keyword_only, default = "None")] - end: Option, + end: Option, #[pyarg(keyword_only, default = "IntoPyBool::FALSE")] flush: IntoPyBool, #[pyarg(keyword_only, default = "None")] @@ -685,11 +685,9 @@ mod decl { Some(f) => f, None => sysmodule::get_stdout(vm)?, }; - let write = |obj: PyStringRef| vm.call_method(&file, "write", vec![obj.into_object()]); + let write = |obj: PyStrRef| vm.call_method(&file, "write", vec![obj.into_object()]); - let sep = options - .sep - .unwrap_or_else(|| PyString::from(" ").into_ref(vm)); + let sep = options.sep.unwrap_or_else(|| PyStr::from(" ").into_ref(vm)); let mut first = true; for object in objects { @@ -704,7 +702,7 @@ mod decl { let end = options .end - .unwrap_or_else(|| PyString::from("\n").into_ref(vm)); + .unwrap_or_else(|| PyStr::from("\n").into_ref(vm)); write(end)?; if options.flush.to_bool() { @@ -715,7 +713,7 @@ mod decl { } #[pyfunction] - fn repr(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn repr(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult { vm.to_repr(&obj) } @@ -759,7 +757,7 @@ mod decl { #[pyfunction] fn setattr( obj: PyObjectRef, - attr: PyStringRef, + attr: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { @@ -804,7 +802,7 @@ mod decl { #[pyfunction] pub fn __build_class__( function: PyFunctionRef, - qualified_name: PyStringRef, + qualified_name: PyStrRef, bases: Args, mut kwargs: KwArgs, vm: &VirtualMachine, diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 0d983907e..0c9112c09 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -15,7 +15,7 @@ use crate::obj::objsequence::{ }; use crate::obj::objsingletons::PyNoneRef; use crate::obj::objslice::PySliceRef; -use crate::obj::objstr::{self, PyString, PyStringRef}; +use crate::obj::objstr::{self, PyStr, PyStrRef}; use crate::pyobject::{ BorrowValue, Either, PyComparisonValue, PyIterable, PyIterator, PyObjectRef, PyResult, TryFromObject, TypeProtocol, @@ -67,9 +67,9 @@ pub struct ByteInnerNewOptions { #[pyarg(positional_or_keyword, optional = true)] source: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] - encoding: OptionalArg, + encoding: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] - errors: OptionalArg, + errors: OptionalArg, } impl ByteInnerNewOptions { @@ -87,7 +87,7 @@ impl ByteInnerNewOptions { } } OptionalArg::Present(obj) => { - match obj.downcast::() { + match obj.downcast::() { Ok(s) => { // Handle bytes(string, encoding[, errors]) if let OptionalArg::Present(enc) = self.encoding { @@ -1188,19 +1188,19 @@ impl<'s> PyCommonString<'s, u8> for [u8] { #[derive(FromArgs)] pub struct DecodeArgs { #[pyarg(positional_or_keyword, default = "None")] - encoding: Option, + encoding: Option, #[pyarg(positional_or_keyword, default = "None")] - errors: Option, + errors: Option, } pub fn bytes_decode( zelf: PyObjectRef, args: DecodeArgs, vm: &VirtualMachine, -) -> PyResult { +) -> PyResult { let DecodeArgs { encoding, errors } = args; vm.decode(zelf, encoding.clone(), errors)? - .downcast::() + .downcast::() .map_err(|obj| { vm.new_type_error(format!( "'{}' decoder returned '{}' instead of 'str'; use codecs.encode() to \ diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 4a33646f3..3d1490d70 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -3,7 +3,7 @@ /// And: https://www.youtube.com/watch?v=p33CVV29OG8 /// And: http://code.activestate.com/recipes/578375/ use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::pyobject::{BorrowValue, IdProtocol, IntoPyObject, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; use rustpython_common::hash; @@ -455,7 +455,7 @@ impl DictKey for PyObjectRef { } } -impl DictKey for PyStringRef { +impl DictKey for PyStrRef { fn key_hash(&self, vm: &VirtualMachine) -> PyResult { Ok(self.hash(vm)) } @@ -467,7 +467,7 @@ impl DictKey for PyStringRef { fn key_eq(&self, vm: &VirtualMachine, other_key: &PyObjectRef) -> PyResult { if self.is(other_key) { Ok(true) - } else if let Some(py_str_value) = other_key.payload::() { + } else if let Some(py_str_value) = other_key.payload::() { Ok(py_str_value.borrow_value() == self.borrow_value()) } else { vm.bool_eq(self.clone().into_object(), other_key.clone()) @@ -481,7 +481,7 @@ impl DictKey for PyStringRef { /// to index dictionaries. impl DictKey for &str { fn key_hash(&self, vm: &VirtualMachine) -> PyResult { - // follow a similar route as the hashing of PyStringRef + // follow a similar route as the hashing of PyStrRef Ok(vm.state.hash_secret.hash_str(*self)) } @@ -492,7 +492,7 @@ impl DictKey for &str { } fn key_eq(&self, vm: &VirtualMachine, other_key: &PyObjectRef) -> PyResult { - if let Some(py_str_value) = other_key.payload::() { + if let Some(py_str_value) = other_key.payload::() { Ok(py_str_value.borrow_value() == *self) } else { // Fall back to PyObjectRef implementation. diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 6341ffe1b..c93ced984 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -1,7 +1,7 @@ use crate::common::cell::PyRwLock; use crate::function::PyFuncArgs; use crate::obj::objsingletons::{PyNone, PyNoneRef}; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtraceback::PyTracebackRef; use crate::obj::objtuple::{PyTuple, PyTupleRef}; use crate::obj::objtype::{self, PyClass, PyClassRef}; @@ -131,12 +131,12 @@ impl PyBaseException { } #[pymethod(name = "__str__")] - fn str(&self, vm: &VirtualMachine) -> PyStringRef { + fn str(&self, vm: &VirtualMachine) -> PyStrRef { let str_args = exception_args_as_string(vm, self.args(), true); match str_args.into_iter().exactly_one() { - Err(i) if i.len() == 0 => PyString::from("").into_ref(vm), + Err(i) if i.len() == 0 => PyStr::from("").into_ref(vm), Ok(s) => s, - Err(i) => PyString::from(format!("({})", i.format(", "))).into_ref(vm), + Err(i) => PyStr::from(format!("({})", i.format(", "))).into_ref(vm), } } @@ -269,17 +269,17 @@ fn exception_args_as_string( vm: &VirtualMachine, varargs: PyTupleRef, str_single: bool, -) -> Vec { +) -> Vec { let varargs = varargs.borrow_value(); match varargs.len() { 0 => vec![], 1 => { let args0_repr = if str_single { vm.to_str(&varargs[0]) - .unwrap_or_else(|_| PyString::from("").into_ref(vm)) + .unwrap_or_else(|_| PyStr::from("").into_ref(vm)) } else { vm.to_repr(&varargs[0]) - .unwrap_or_else(|_| PyString::from("").into_ref(vm)) + .unwrap_or_else(|_| PyStr::from("").into_ref(vm)) }; vec![args0_repr] } @@ -287,7 +287,7 @@ fn exception_args_as_string( .iter() .map(|vararg| { vm.to_repr(vararg) - .unwrap_or_else(|_| PyString::from("").into_ref(vm)) + .unwrap_or_else(|_| PyStr::from("").into_ref(vm)) }) .collect(), } @@ -644,7 +644,7 @@ fn make_arg_getter(idx: usize) -> impl Fn(PyBaseExceptionRef) -> Option PyStringRef { +fn key_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef { let args = exc.args(); if args.borrow_value().len() == 1 { exception_args_as_string(vm, args, false) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 7df58c4c2..097fb61e2 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -19,7 +19,7 @@ use crate::obj::objgenerator::PyGenerator; use crate::obj::objiter; use crate::obj::objlist; use crate::obj::objslice::PySlice; -use crate::obj::objstr::{self, PyString, PyStringRef}; +use crate::obj::objstr::{self, PyStr, PyStrRef}; use crate::obj::objtraceback::PyTraceback; use crate::obj::objtuple::PyTuple; use crate::obj::objtype::{self, PyClassRef}; @@ -797,7 +797,7 @@ impl ExecutingFrame<'_> { if let Some(dict) = module.dict() { let filter_pred: Box bool> = if let Ok(all) = dict.get_item("__all__", vm) { - let all: Vec = vm.extract_elements(&all)?; + let all: Vec = vm.extract_elements(&all)?; let all: Vec = all .into_iter() .map(|name| name.as_ref().to_owned()) @@ -807,7 +807,7 @@ impl ExecutingFrame<'_> { Box::new(|name| !name.starts_with('_')) }; for (k, v) in &dict { - let k = PyStringRef::try_from_object(vm, k)?; + let k = PyStrRef::try_from_object(vm, k)?; let k = k.as_ref(); if filter_pred(k) { self.scope.store_name(&vm, k, v); @@ -1063,23 +1063,24 @@ impl ExecutingFrame<'_> { PyFuncArgs::new(args, kwarg_names) } bytecode::CallType::Ex(has_kwargs) => { - let kwargs = - if *has_kwargs { - let kw_dict: PyDictRef = self.pop_value().downcast().map_err(|_| { - // TODO: check collections.abc.Mapping - vm.new_type_error("Kwargs must be a dict.".to_owned()) - })?; - let mut kwargs = IndexMap::new(); - for (key, value) in kw_dict.into_iter() { - let key = key.payload_if_subclass::(vm).ok_or_else( - || vm.new_type_error("keywords must be strings".to_owned()), - )?; - kwargs.insert(key.borrow_value().to_owned(), value); - } - kwargs - } else { - IndexMap::new() - }; + let kwargs = if *has_kwargs { + let kw_dict: PyDictRef = self.pop_value().downcast().map_err(|_| { + // TODO: check collections.abc.Mapping + vm.new_type_error("Kwargs must be a dict.".to_owned()) + })?; + let mut kwargs = IndexMap::new(); + for (key, value) in kw_dict.into_iter() { + let key = + key.payload_if_subclass::(vm) + .ok_or_else(|| { + vm.new_type_error("keywords must be strings".to_owned()) + })?; + kwargs.insert(key.borrow_value().to_owned(), value); + } + kwargs + } else { + IndexMap::new() + }; let args = self.pop_value(); let args = vm.extract_elements(&args)?; PyFuncArgs { args, kwargs } @@ -1243,7 +1244,7 @@ impl ExecutingFrame<'_> { fn execute_make_function(&mut self, vm: &VirtualMachine) -> FrameResult { let qualified_name = self .pop_value() - .downcast::() + .downcast::() .expect("qualified name to be a string"); let code_obj: PyCodeRef = self .pop_value() diff --git a/vm/src/function.rs b/vm/src/function.rs index 6d9268b7c..f534d20ce 100644 --- a/vm/src/function.rs +++ b/vm/src/function.rs @@ -487,7 +487,7 @@ pub type PyNativeFunc = Box Py /// /// For example, anything from `Fn()` to `Fn(vm: &VirtualMachine) -> u32` to /// `Fn(PyIntRef, PyIntRef) -> String` to -/// `Fn(&self, PyStringRef, FooOptions, vm: &VirtualMachine) -> PyResult` +/// `Fn(&self, PyStrRef, FooOptions, vm: &VirtualMachine) -> PyResult` /// is `IntoPyNativeFunc`. If you do want a really general function signature, e.g. /// to forward the args to another function, you can define a function like /// `Fn(PyFuncArgs [, &VirtualMachine]) -> ...` diff --git a/vm/src/obj/objbool.rs b/vm/src/obj/objbool.rs index fd9e29c84..be71c2b4b 100644 --- a/vm/src/obj/objbool.rs +++ b/vm/src/obj/objbool.rs @@ -9,7 +9,7 @@ use crate::pyobject::{ use crate::vm::VirtualMachine; use super::objint::PyInt; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype; impl IntoPyObject for bool { @@ -92,11 +92,7 @@ impl PyBool { } #[pymethod(magic)] - fn format( - obj: PyObjectRef, - format_spec: PyStringRef, - vm: &VirtualMachine, - ) -> PyResult { + fn format(obj: PyObjectRef, format_spec: PyStrRef, vm: &VirtualMachine) -> PyResult { if format_spec.borrow_value().is_empty() { vm.to_str(&obj) } else { diff --git a/vm/src/obj/objbuiltinfunc.rs b/vm/src/obj/objbuiltinfunc.rs index 4c9b6ee95..a90b91fe7 100644 --- a/vm/src/obj/objbuiltinfunc.rs +++ b/vm/src/obj/objbuiltinfunc.rs @@ -2,7 +2,7 @@ use std::fmt; use super::objclassmethod::PyClassMethod; use crate::function::{PyFuncArgs, PyNativeFunc}; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ PyClassImpl, PyContext, PyObject, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol, @@ -12,8 +12,8 @@ use crate::vm::VirtualMachine; pub struct PyFuncDef { pub func: PyNativeFunc, - pub name: Option, - pub doc: Option, + pub name: Option, + pub doc: Option, } impl From for PyFuncDef { @@ -119,11 +119,11 @@ impl PyBuiltinFunction { vm.unwrap_or_none(self.module.clone()) } #[pyproperty(magic)] - fn name(&self) -> Option { + fn name(&self) -> Option { self.value.name.clone() } #[pyproperty(magic)] - fn doc(&self) -> Option { + fn doc(&self) -> Option { self.value.doc.clone() } } @@ -152,7 +152,7 @@ impl From for PyBuiltinMethod { } impl PyBuiltinMethod { - pub fn new_with_name(func: PyNativeFunc, name: PyStringRef) -> Self { + pub fn new_with_name(func: PyNativeFunc, name: PyStrRef) -> Self { Self { value: PyFuncDef { func, @@ -195,11 +195,11 @@ impl Callable for PyBuiltinMethod { #[pyimpl(with(SlotDescriptor, Callable))] impl PyBuiltinMethod { #[pyproperty(magic)] - fn name(&self) -> Option { + fn name(&self) -> Option { self.value.name.clone() } #[pyproperty(magic)] - fn doc(&self) -> Option { + fn doc(&self) -> Option { self.value.doc.clone() } } diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index 8823f4071..b1d4fd225 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -6,7 +6,7 @@ use std::mem::size_of; use super::objint::PyIntRef; use super::objiter; use super::objsequence::SequenceIndex; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::PyClassRef; use crate::bytesinner::{ bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, @@ -246,7 +246,7 @@ impl PyByteArray { } #[pymethod] - fn fromhex(string: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn fromhex(string: PyStrRef, vm: &VirtualMachine) -> PyResult { Ok(PyBytesInner::fromhex(string.borrow_value(), vm)?.into()) } @@ -528,7 +528,7 @@ impl PyByteArray { } #[pymethod] - fn decode(zelf: PyRef, args: DecodeArgs, vm: &VirtualMachine) -> PyResult { + fn decode(zelf: PyRef, args: DecodeArgs, vm: &VirtualMachine) -> PyResult { bytes_decode(zelf.into_object(), args, vm) } diff --git a/vm/src/obj/objbytes.rs b/vm/src/obj/objbytes.rs index 4d46649e3..3a6c1bab1 100644 --- a/vm/src/obj/objbytes.rs +++ b/vm/src/obj/objbytes.rs @@ -6,7 +6,7 @@ use std::ops::Deref; use super::objint::PyIntRef; use super::objiter; use super::objsequence::SequenceIndex; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::PyClassRef; use crate::bytesinner::{ bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, @@ -209,7 +209,7 @@ impl PyBytes { } #[pymethod] - fn fromhex(string: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn fromhex(string: PyStrRef, vm: &VirtualMachine) -> PyResult { Ok(PyBytesInner::fromhex(string.borrow_value(), vm)?.into()) } @@ -440,7 +440,7 @@ impl PyBytes { /// see https://docs.python.org/3/library/codecs.html#standard-encodings /// currently, only 'utf-8' and 'ascii' emplemented #[pymethod] - fn decode(zelf: PyRef, args: DecodeArgs, vm: &VirtualMachine) -> PyResult { + fn decode(zelf: PyRef, args: DecodeArgs, vm: &VirtualMachine) -> PyResult { bytes_decode(zelf.into_object(), args, vm) } diff --git a/vm/src/obj/objcomplex.rs b/vm/src/obj/objcomplex.rs index d67a59f9e..6603d4fcb 100644 --- a/vm/src/obj/objcomplex.rs +++ b/vm/src/obj/objcomplex.rs @@ -2,7 +2,7 @@ use num_complex::Complex64; use num_traits::Zero; use super::objfloat; -use super::objstr::PyString; +use super::objstr::PyStr; use super::objtype::{self, PyClassRef}; use crate::pyobject::{ BorrowValue, IntoPyObject, Never, PyArithmaticValue, PyClassImpl, PyComparisonValue, PyContext, @@ -229,7 +229,7 @@ impl PyComplex { Some(obj) => { if let Some(c) = try_complex(&obj, vm)? { c - } else if let Some(s) = obj.payload_if_subclass::(vm) { + } else if let Some(s) = obj.payload_if_subclass::(vm) { if args.imag.is_some() { return Err(vm.new_type_error( "complex() can't take second arg if first is a string".to_owned(), diff --git a/vm/src/obj/objcoroutine.rs b/vm/src/obj/objcoroutine.rs index 313fcb1a6..c309e1032 100644 --- a/vm/src/obj/objcoroutine.rs +++ b/vm/src/obj/objcoroutine.rs @@ -1,6 +1,6 @@ use super::objcode::PyCodeRef; use super::objcoroinner::{Coro, Variant}; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::PyClassRef; use crate::frame::FrameRef; use crate::function::OptionalArg; @@ -90,7 +90,7 @@ impl PyCoroutine { // TODO: coroutine origin tracking: // https://docs.python.org/3/library/sys.html#sys.set_coroutine_origin_tracking_depth #[pyproperty] - fn cr_origin(&self, _vm: &VirtualMachine) -> Option<(PyStringRef, usize, PyStringRef)> { + fn cr_origin(&self, _vm: &VirtualMachine) -> Option<(PyStrRef, usize, PyStrRef)> { None } } diff --git a/vm/src/obj/objdict.rs b/vm/src/obj/objdict.rs index 7023015f7..761b36a4c 100644 --- a/vm/src/obj/objdict.rs +++ b/vm/src/obj/objdict.rs @@ -467,7 +467,7 @@ impl PyDictRef { // Test if this object is a true dict, or mabye a subclass? // If it is a dict, we can directly invoke inner_get_item_option, // and prevent the creation of the KeyError exception. - // Also note, that we prevent the creation of a full PyString object + // Also note, that we prevent the creation of a full PyStr object // if we lookup local names (which happens all of the time). if self.lease_class().is(&vm.ctx.types.dict_type) { // We can take the short path here! diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index 4488f15a6..fcab6ae9d 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -5,7 +5,7 @@ use num_traits::{pow, ToPrimitive, Zero}; use super::objbytes::PyBytes; use super::objint::{self, PyInt, PyIntRef}; -use super::objstr::{PyString, PyStringRef}; +use super::objstr::{PyStr, PyStrRef}; use super::objtype::PyClassRef; use crate::format::FormatSpec; use crate::function::{OptionalArg, OptionalOption}; @@ -149,7 +149,7 @@ impl PyFloat { } #[pymethod(name = "__format__")] - fn format(&self, spec: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn format(&self, spec: PyStrRef, vm: &VirtualMachine) -> PyResult { match FormatSpec::parse(spec.borrow_value()) .and_then(|format_spec| format_spec.format_float(self.value)) { @@ -432,7 +432,7 @@ impl PyFloat { } #[pymethod] - fn fromhex(repr: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn fromhex(repr: PyStrRef, vm: &VirtualMachine) -> PyResult { float_ops::from_hex(repr.borrow_value().trim()).ok_or_else(|| { vm.new_value_error("invalid hexadecimal floating-point string".to_owned()) }) @@ -496,7 +496,7 @@ fn to_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { float.value } else if let Some(int) = obj.payload_if_subclass::(vm) { objint::try_float(int.borrow_value(), vm)? - } else if let Some(s) = obj.payload_if_subclass::(vm) { + } else if let Some(s) = obj.payload_if_subclass::(vm) { float_ops::parse_str(s.borrow_value().trim()).ok_or_else(|| { vm.new_value_error(format!("could not convert string to float: '{}'", s)) })? diff --git a/vm/src/obj/objframe.rs b/vm/src/obj/objframe.rs index b8392b827..4e92fbc52 100644 --- a/vm/src/obj/objframe.rs +++ b/vm/src/obj/objframe.rs @@ -4,7 +4,7 @@ use super::objcode::PyCodeRef; use super::objdict::PyDictRef; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use crate::frame::FrameRef; use crate::pyobject::{IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; @@ -26,7 +26,7 @@ impl FrameRef { } #[pymethod(name = "__delattr__")] - fn delattr(self, value: PyStringRef, vm: &VirtualMachine) { + fn delattr(self, value: PyStrRef, vm: &VirtualMachine) { // CPython' Frame.f_trace is set to None when deleted. // The strange behavior is mimicked here make bdb.py happy about it. if value.to_string() == "f_trace" { diff --git a/vm/src/obj/objfunction.rs b/vm/src/obj/objfunction.rs index 4e1be30c9..ffbefb416 100644 --- a/vm/src/obj/objfunction.rs +++ b/vm/src/obj/objfunction.rs @@ -3,7 +3,7 @@ mod jitfunc; use super::objcode::PyCodeRef; use super::objdict::PyDictRef; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtuple::PyTupleRef; use super::objtype::PyClassRef; use crate::bytecode; @@ -377,7 +377,7 @@ impl PyBoundMethod { } #[pymethod(magic)] - fn getattribute(zelf: PyRef, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(zelf: PyRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Some(obj) = zelf.get_class_attr(name.borrow_value()) { return vm.call_if_get_descriptor(obj, zelf.into_object()); } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 271e20597..618c90f62 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -12,7 +12,7 @@ use super::objbytearray::PyByteArray; use super::objbytes::PyBytes; use super::objfloat; use super::objmemory::PyMemoryView; -use super::objstr::{PyString, PyStringRef}; +use super::objstr::{PyStr, PyStrRef}; use super::objtype::PyClassRef; use crate::bytesinner::PyBytesInner; use crate::format::FormatSpec; @@ -518,7 +518,7 @@ impl PyInt { } #[pymethod(name = "__format__")] - fn format(&self, spec: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn format(&self, spec: PyStrRef, vm: &VirtualMachine) -> PyResult { match FormatSpec::parse(spec.borrow_value()) .and_then(|format_spec| format_spec.format_int(&self.value)) { @@ -702,7 +702,7 @@ struct IntFromByteArgs { #[pyarg(positional_or_keyword)] bytes: PyBytesInner, #[pyarg(positional_or_keyword)] - byteorder: PyStringRef, + byteorder: PyStrRef, #[pyarg(keyword_only, optional = true)] signed: OptionalArg, } @@ -712,7 +712,7 @@ struct IntToByteArgs { #[pyarg(positional_or_keyword)] length: PyIntRef, #[pyarg(positional_or_keyword)] - byteorder: PyStringRef, + byteorder: PyStrRef, #[pyarg(keyword_only, optional = true)] signed: OptionalArg, } @@ -721,7 +721,7 @@ struct IntToByteArgs { pub(crate) fn to_int(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult { let base = 10; let opt = match_class!(match obj.clone() { - string @ PyString => { + string @ PyStr => { let s = string.borrow_value(); bytes_to_int(s.as_bytes(), base) } @@ -774,7 +774,7 @@ fn to_int_radix(vm: &VirtualMachine, obj: &PyObjectRef, base: u32) -> PyResult { + string @ PyStr => { let s = string.borrow_value(); bytes_to_int(s.as_bytes(), base) } diff --git a/vm/src/obj/objmappingproxy.rs b/vm/src/obj/objmappingproxy.rs index bf6e66eb0..f958598ea 100644 --- a/vm/src/obj/objmappingproxy.rs +++ b/vm/src/obj/objmappingproxy.rs @@ -1,6 +1,6 @@ use super::objdict::PyDict; use super::objiter; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::PyClassRef; use crate::function::OptionalArg; use crate::pyobject::{ @@ -48,7 +48,7 @@ impl PyMappingProxy { fn get_inner(&self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult> { let opt = match &self.mapping { MappingProxyInner::Class(class) => { - let key = PyStringRef::try_from_object(vm, key)?; + let key = PyStrRef::try_from_object(vm, key)?; class.get_attr(key.borrow_value()) } MappingProxyInner::Dict(obj) => obj.get_item(key, vm).ok(), @@ -78,7 +78,7 @@ impl PyMappingProxy { pub fn contains(&self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult { match &self.mapping { MappingProxyInner::Class(class) => { - let key = PyStringRef::try_from_object(vm, key)?; + let key = PyStrRef::try_from_object(vm, key)?; Ok(vm.ctx.new_bool(class.has_attr(key.borrow_value()))) } MappingProxyInner::Dict(obj) => vm._membership(obj.clone(), key), diff --git a/vm/src/obj/objmodule.rs b/vm/src/obj/objmodule.rs index 994c5fe0b..6817bffb4 100644 --- a/vm/src/obj/objmodule.rs +++ b/vm/src/obj/objmodule.rs @@ -1,5 +1,5 @@ use super::objdict::PyDictRef; -use super::objstr::{PyString, PyStringRef}; +use super::objstr::{PyStr, PyStrRef}; use super::objtype::PyClassRef; use crate::function::{OptionalOption, PyFuncArgs}; use crate::pyobject::{ @@ -52,8 +52,8 @@ impl PyModuleRef { #[pymethod(magic)] fn init( self, - name: PyStringRef, - doc: OptionalOption, + name: PyStrRef, + doc: OptionalOption, vm: &VirtualMachine, ) -> PyResult<()> { debug_assert!(crate::pyobject::TypeProtocol::lease_class(self.as_object()) @@ -72,18 +72,15 @@ impl PyModuleRef { fn name(self, vm: &VirtualMachine) -> Option { vm.generic_getattribute_opt( self.as_object().clone(), - PyString::from("__name__").into_ref(vm), + PyStr::from("__name__").into_ref(vm), None, ) .unwrap_or(None) - .and_then(|obj| { - obj.payload::() - .map(|s| s.borrow_value().to_owned()) - }) + .and_then(|obj| obj.payload::().map(|s| s.borrow_value().to_owned())) } #[pymethod(magic)] - fn getattribute(self, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(self, name: PyStrRef, vm: &VirtualMachine) -> PyResult { vm.generic_getattribute_opt(self.as_object().clone(), name.clone(), None)? .ok_or_else(|| { let module_name = if let Some(name) = self.name(vm) { diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index f0d33d818..a6a4c3223 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -1,7 +1,7 @@ use super::objbool; use super::objdict::{PyDict, PyDictRef}; use super::objlist::PyList; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::PyClassRef; use crate::common::hash::PyHash; use crate::function::{OptionalArg, PyFuncArgs}; @@ -132,7 +132,7 @@ impl PyBaseObject { #[pymethod(magic)] pub(crate) fn setattr( obj: PyObjectRef, - attr_name: PyStringRef, + attr_name: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { @@ -140,7 +140,7 @@ impl PyBaseObject { } #[pymethod(magic)] - fn delattr(obj: PyObjectRef, attr_name: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn delattr(obj: PyObjectRef, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { if let Some(attr) = obj.get_class_attr(attr_name.borrow_value()) { if let Some(descriptor) = attr.get_class_attr("__delete__") { return vm.invoke(&descriptor, vec![attr, obj]).map(|_| ()); @@ -198,11 +198,7 @@ impl PyBaseObject { } #[pymethod(magic)] - fn format( - obj: PyObjectRef, - format_spec: PyStringRef, - vm: &VirtualMachine, - ) -> PyResult { + fn format(obj: PyObjectRef, format_spec: PyStrRef, vm: &VirtualMachine) -> PyResult { if format_spec.borrow_value().is_empty() { vm.to_str(&obj) } else { @@ -245,7 +241,7 @@ impl PyBaseObject { } #[pymethod(magic)] - fn getattribute(obj: PyObjectRef, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(obj: PyObjectRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { vm_trace!("object.__getattribute__({:?}, {:?})", obj, name); vm.generic_getattribute(obj, name) } @@ -289,7 +285,7 @@ pub fn object_set_dict(obj: PyObjectRef, dict: PyDictRef, vm: &VirtualMachine) - #[cfg_attr(feature = "flame-it", flame)] pub(crate) fn setattr( obj: PyObjectRef, - attr_name: PyStringRef, + attr_name: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 0ed998145..53f12ab54 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -44,13 +44,13 @@ use rustpython_common::hash; /// errors defaults to 'strict'." #[pyclass(module = false, name = "str")] #[derive(Debug)] -pub struct PyString { +pub struct PyStr { value: String, hash: AtomicCell>, len: AtomicCell>, } -impl<'a> BorrowValue<'a> for PyString { +impl<'a> BorrowValue<'a> for PyStr { type Borrowed = &'a str; fn borrow_value(&'a self) -> Self::Borrowed { @@ -58,24 +58,24 @@ impl<'a> BorrowValue<'a> for PyString { } } -impl AsRef for PyString { +impl AsRef for PyStr { fn as_ref(&self) -> &str { &self.value } } -impl From<&T> for PyString +impl From<&T> for PyStr where T: AsRef + ?Sized, { - fn from(s: &T) -> PyString { + fn from(s: &T) -> PyStr { s.as_ref().to_owned().into() } } -impl From for PyString { - fn from(s: String) -> PyString { - PyString { +impl From for PyStr { + fn from(s: String) -> PyStr { + PyStr { value: s, hash: AtomicCell::default(), len: AtomicCell::default(), @@ -83,30 +83,30 @@ impl From for PyString { } } -pub type PyStringRef = PyRef; +pub type PyStrRef = PyRef; -impl fmt::Display for PyString { +impl fmt::Display for PyStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.value, f) } } -impl TryIntoRef for String { - fn try_into_ref(self, vm: &VirtualMachine) -> PyResult> { - Ok(PyString::from(self).into_ref(vm)) +impl TryIntoRef for String { + fn try_into_ref(self, vm: &VirtualMachine) -> PyResult> { + Ok(PyStr::from(self).into_ref(vm)) } } -impl TryIntoRef for &str { - fn try_into_ref(self, vm: &VirtualMachine) -> PyResult> { - Ok(PyString::from(self).into_ref(vm)) +impl TryIntoRef for &str { + fn try_into_ref(self, vm: &VirtualMachine) -> PyResult> { + Ok(PyStr::from(self).into_ref(vm)) } } #[pyclass(module = false, name = "str_iterator")] #[derive(Debug)] pub struct PyStringIterator { - pub string: PyStringRef, + pub string: PyStrRef, position: AtomicCell, } @@ -140,7 +140,7 @@ impl PyStringIterator { #[derive(Debug)] pub struct PyStringReverseIterator { pub position: AtomicCell, - pub string: PyStringRef, + pub string: PyStrRef, } impl PyValue for PyStringReverseIterator { @@ -173,16 +173,16 @@ struct StrArgs { #[pyarg(positional_or_keyword, optional = true)] object: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] - encoding: OptionalArg, + encoding: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] - errors: OptionalArg, + errors: OptionalArg, } #[pyimpl(flags(BASETYPE), with(Hashable, Comparable))] -impl PyString { +impl PyStr { #[pyslot] - fn tp_new(cls: PyClassRef, args: StrArgs, vm: &VirtualMachine) -> PyResult { - let string: PyStringRef = match args.object { + fn tp_new(cls: PyClassRef, args: StrArgs, vm: &VirtualMachine) -> PyResult { + let string: PyStrRef = match args.object { OptionalArg::Present(input) => { if let OptionalArg::Present(enc) = args.encoding { vm.decode(input, Some(enc.clone()), args.errors.into_option())? @@ -200,13 +200,13 @@ impl PyString { } } OptionalArg::Missing => { - PyString::from(String::new()).into_ref_with_type(vm, cls.clone())? + PyStr::from(String::new()).into_ref_with_type(vm, cls.clone())? } }; if string.class().is(&cls) { Ok(string) } else { - PyString::from(string.borrow_value()).into_ref_with_type(vm, cls) + PyStr::from(string.borrow_value()).into_ref_with_type(vm, cls) } } @@ -225,7 +225,7 @@ impl PyString { } #[pymethod(name = "__contains__")] - fn contains(&self, needle: PyStringRef) -> bool { + fn contains(&self, needle: PyStrRef) -> bool { self.value.contains(&needle.value) } @@ -282,7 +282,7 @@ impl PyString { } #[pymethod(name = "__str__")] - fn str(zelf: PyRef) -> PyStringRef { + fn str(zelf: PyRef) -> PyStrRef { zelf } @@ -435,7 +435,7 @@ impl PyString { } #[pymethod] - fn strip(&self, chars: OptionalOption) -> String { + fn strip(&self, chars: OptionalOption) -> String { self.value .py_strip( chars, @@ -446,7 +446,7 @@ impl PyString { } #[pymethod] - fn lstrip(&self, chars: OptionalOption) -> String { + fn lstrip(&self, chars: OptionalOption) -> String { self.value .py_strip( chars, @@ -457,7 +457,7 @@ impl PyString { } #[pymethod] - fn rstrip(&self, chars: OptionalOption) -> String { + fn rstrip(&self, chars: OptionalOption) -> String { self.value .py_strip( chars, @@ -473,7 +473,7 @@ impl PyString { args, "endswith", "str", - |s, x: &PyStringRef| s.ends_with(x.borrow_value()), + |s, x: &PyStrRef| s.ends_with(x.borrow_value()), vm, ) } @@ -484,7 +484,7 @@ impl PyString { args, "startswith", "str", - |s, x: &PyStringRef| s.starts_with(x.borrow_value()), + |s, x: &PyStrRef| s.starts_with(x.borrow_value()), vm, ) } @@ -497,7 +497,7 @@ impl PyString { /// If the string starts with the prefix string, return string[len(prefix):] /// Otherwise, return a copy of the original string. #[pymethod] - fn removeprefix(&self, pref: PyStringRef) -> String { + fn removeprefix(&self, pref: PyStrRef) -> String { self.value .py_removeprefix(&pref.value, pref.value.len(), |s, p| s.starts_with(p)) .to_owned() @@ -511,7 +511,7 @@ impl PyString { /// If the string ends with the suffix string, return string[:len(suffix)] /// Otherwise, return a copy of the original string. #[pymethod] - fn removesuffix(&self, suff: PyStringRef) -> String { + fn removesuffix(&self, suff: PyStrRef) -> String { self.value .py_removesuffix(&suff.value, suff.value.len(), |s, p| s.ends_with(p)) .to_owned() @@ -579,7 +579,7 @@ impl PyString { } #[pymethod(name = "__format__")] - fn format_str(&self, spec: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn format_str(&self, spec: PyStrRef, vm: &VirtualMachine) -> PyResult { match FormatSpec::parse(spec.borrow_value()) .and_then(|format_spec| format_spec.format_string(&self.value)) { @@ -639,7 +639,7 @@ impl PyString { } #[pymethod] - fn replace(&self, old: PyStringRef, new: PyStringRef, count: OptionalArg) -> String { + fn replace(&self, old: PyStrRef, new: PyStrRef, count: OptionalArg) -> String { match count { OptionalArg::Present(maxcount) if maxcount >= 0 => { if maxcount == 0 || self.value.is_empty() { @@ -711,7 +711,7 @@ impl PyString { } #[pymethod] - fn join(&self, iterable: PyIterable, vm: &VirtualMachine) -> PyResult { + fn join(&self, iterable: PyIterable, vm: &VirtualMachine) -> PyResult { let iter = iterable.iter(vm)?; self.value.py_join(iter) } @@ -750,7 +750,7 @@ impl PyString { } #[pymethod] - fn partition(&self, sep: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn partition(&self, sep: PyStrRef, vm: &VirtualMachine) -> PyResult { let (front, has_mid, back) = self.value .py_partition(&sep.value, || self.value.splitn(2, &sep.value), vm)?; @@ -766,7 +766,7 @@ impl PyString { } #[pymethod] - fn rpartition(&self, sep: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn rpartition(&self, sep: PyStrRef, vm: &VirtualMachine) -> PyResult { let (back, has_mid, front) = self.value .py_partition(&sep.value, || self.value.rsplitn(2, &sep.value), vm)?; @@ -828,7 +828,7 @@ impl PyString { fn _pad( &self, width: isize, - fillchar: OptionalArg, + fillchar: OptionalArg, pad: fn(&str, usize, char, usize) -> String, vm: &VirtualMachine, ) -> PyResult { @@ -851,7 +851,7 @@ impl PyString { fn center( &self, width: isize, - fillchar: OptionalArg, + fillchar: OptionalArg, vm: &VirtualMachine, ) -> PyResult { self._pad(width, fillchar, PyCommonString::::py_center, vm) @@ -861,7 +861,7 @@ impl PyString { fn ljust( &self, width: isize, - fillchar: OptionalArg, + fillchar: OptionalArg, vm: &VirtualMachine, ) -> PyResult { self._pad(width, fillchar, PyCommonString::::py_ljust, vm) @@ -871,7 +871,7 @@ impl PyString { fn rjust( &self, width: isize, - fillchar: OptionalArg, + fillchar: OptionalArg, vm: &VirtualMachine, ) -> PyResult { self._pad(width, fillchar, PyCommonString::::py_rjust, vm) @@ -927,7 +927,7 @@ impl PyString { for c in self.value.chars() { match table.get_item((c as u32).into_pyobject(vm), vm) { Ok(value) => { - if let Some(text) = value.payload::() { + if let Some(text) = value.payload::() { translated.push_str(&text.value); } else if let Some(bigint) = value.payload::() { let ch = bigint @@ -955,13 +955,13 @@ impl PyString { #[pymethod] fn maketrans( dict_or_str: PyObjectRef, - to_str: OptionalArg, - none_str: OptionalArg, + to_str: OptionalArg, + none_str: OptionalArg, vm: &VirtualMachine, ) -> PyResult { let new_dict = vm.ctx.new_dict(); if let OptionalArg::Present(to_str) = to_str { - match dict_or_str.downcast::() { + match dict_or_str.downcast::() { Ok(from_str) => { if to_str.len() == from_str.len() { for (c1, c2) in from_str.value.chars().zip(to_str.value.chars()) { @@ -999,7 +999,7 @@ impl PyString { val, vm, )?; - } else if let Some(string) = key.payload::() { + } else if let Some(string) = key.payload::() { 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)?; @@ -1043,13 +1043,13 @@ impl PyString { } } -impl Hashable for PyString { +impl Hashable for PyStr { fn hash(zelf: &PyRef, vm: &VirtualMachine) -> PyResult { Ok(zelf.hash(vm)) } } -impl Comparable for PyString { +impl Comparable for PyStr { fn cmp( zelf: PyRef, other: PyObjectRef, @@ -1069,15 +1069,15 @@ impl Comparable for PyString { #[derive(FromArgs)] struct EncodeArgs { #[pyarg(positional_or_keyword, default = "None")] - encoding: Option, + encoding: Option, #[pyarg(positional_or_keyword, default = "None")] - errors: Option, + errors: Option, } pub(crate) fn encode_string( - s: PyStringRef, - encoding: Option, - errors: Option, + s: PyStrRef, + encoding: Option, + errors: Option, vm: &VirtualMachine, ) -> PyResult { vm.encode(s.into_object(), encoding.clone(), errors)? @@ -1092,7 +1092,7 @@ pub(crate) fn encode_string( }) } -impl PyValue for PyString { +impl PyValue for PyStr { fn class(vm: &VirtualMachine) -> PyClassRef { vm.ctx.types.str_type.clone() } @@ -1118,7 +1118,7 @@ impl IntoPyObject for &String { impl TryFromObject for std::ffi::CString { fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { - let s = PyStringRef::try_from_object(vm, obj)?; + let s = PyStrRef::try_from_object(vm, obj)?; Self::new(s.borrow_value().to_owned()) .map_err(|_| vm.new_value_error("embedded null character".to_owned())) } @@ -1128,17 +1128,17 @@ impl TryFromObject for std::ffi::OsString { fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { use std::str::FromStr; - let s = PyStringRef::try_from_object(vm, obj)?; + let s = PyStrRef::try_from_object(vm, obj)?; Ok(std::ffi::OsString::from_str(s.borrow_value()).unwrap()) } } -type SplitArgs<'a> = pystr::SplitArgs<'a, PyStringRef, str, char>; +type SplitArgs<'a> = pystr::SplitArgs<'a, PyStrRef, str, char>; #[derive(FromArgs)] pub struct FindArgs { #[pyarg(positional_only, optional = false)] - sub: PyStringRef, + sub: PyStrRef, #[pyarg(positional_only, default = "None")] start: Option, #[pyarg(positional_only, default = "None")] @@ -1146,28 +1146,28 @@ pub struct FindArgs { } impl FindArgs { - fn get_value(self, len: usize) -> (PyStringRef, std::ops::Range) { + fn get_value(self, len: usize) -> (PyStrRef, std::ops::Range) { let range = adjust_indices(self.start, self.end, len); (self.sub, range) } } pub fn init(ctx: &PyContext) { - PyString::extend_class(ctx, &ctx.types.str_type); + PyStr::extend_class(ctx, &ctx.types.str_type); PyStringIterator::extend_class(ctx, &ctx.types.str_iterator_type); PyStringReverseIterator::extend_class(ctx, &ctx.types.str_reverseiterator_type); } pub fn clone_value(obj: &PyObjectRef) -> String { - obj.payload::().unwrap().value.clone() + obj.payload::().unwrap().value.clone() } pub fn borrow_value(obj: &PyObjectRef) -> &str { - &obj.payload::().unwrap().value + &obj.payload::().unwrap().value } -impl PySliceableSequence for PyString { +impl PySliceableSequence for PyStr { type Sliced = String; fn do_slice(&self, range: Range) -> Self::Sliced { @@ -1253,7 +1253,7 @@ mod tests { ("Greek ῼitlecases ...", "greek ῳitlecases ..."), ]; for (title, input) in tests { - assert_eq!(PyString::from(input).title().as_str(), title); + assert_eq!(PyStr::from(input).title().as_str(), title); } } @@ -1269,7 +1269,7 @@ mod tests { ]; for s in pos { - assert!(PyString::from(s).istitle()); + assert!(PyStr::from(s).istitle()); } let neg = vec![ @@ -1282,7 +1282,7 @@ mod tests { "NOT", ]; for s in neg { - assert!(!PyString::from(s).istitle()); + assert!(!PyStr::from(s).istitle()); } } @@ -1293,14 +1293,14 @@ mod tests { table.set_item("a", vm.ctx.new_str("🎅"), &vm).unwrap(); table.set_item("b", vm.ctx.none(), &vm).unwrap(); table.set_item("c", vm.ctx.new_str("xda"), &vm).unwrap(); - let translated = PyString::maketrans( + let translated = PyStr::maketrans( table.into_object(), OptionalArg::Missing, OptionalArg::Missing, &vm, ) .unwrap(); - let text = PyString::from("abc"); + let text = PyStr::from("abc"); let translated = text.translate(translated, &vm).unwrap(); assert_eq!(translated, "🎅xda".to_owned()); let translated = text.translate(vm.ctx.new_int(3), &vm); @@ -1312,7 +1312,7 @@ mod tests { } } -impl PyCommonStringWrapper for PyStringRef { +impl PyCommonStringWrapper for PyStrRef { fn as_ref(&self) -> &str { self.value.as_str() } diff --git a/vm/src/obj/objsuper.rs b/vm/src/obj/objsuper.rs index 441cc5612..dc1523b2d 100644 --- a/vm/src/obj/objsuper.rs +++ b/vm/src/obj/objsuper.rs @@ -6,7 +6,7 @@ https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/ */ -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtype::{self, PyClass, PyClassRef}; use crate::function::OptionalArg; use crate::pyobject::{ @@ -56,7 +56,7 @@ impl PySuper { } #[pymethod(name = "__getattribute__")] - fn getattribute(zelf: PyRef, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(zelf: PyRef, name: PyStrRef, vm: &VirtualMachine) -> PyResult { let (inst, obj_type) = match zelf.obj.clone() { Some(o) => o, None => return vm.generic_getattribute(zelf.into_object(), name), diff --git a/vm/src/obj/objtype.rs b/vm/src/obj/objtype.rs index daacc2744..f6c5a3e8d 100644 --- a/vm/src/obj/objtype.rs +++ b/vm/src/obj/objtype.rs @@ -9,7 +9,7 @@ use super::objlist::PyList; use super::objmappingproxy::PyMappingProxy; use super::objobject; use super::objstaticmethod::PyStaticMethod; -use super::objstr::PyStringRef; +use super::objstr::PyStrRef; use super::objtuple::PyTuple; use super::objweakref::PyWeak; use crate::function::{KwArgs, PyFuncArgs}; @@ -63,7 +63,7 @@ impl PyClassRef { let module = zelf.attributes.read().get("__module__").cloned(); let new_name = if let Some(module) = module { // FIXME: "unknown" case is a bug. - let module_str = PyStringRef::try_from_object(vm, module) + let module_str = PyStrRef::try_from_object(vm, module) .map_or("".to_owned(), |m| m.borrow_value().to_owned()); format!("{}.{}", module_str, &zelf.name) } else { @@ -261,12 +261,12 @@ impl PyClass { } #[pymethod(magic)] - fn prepare(_name: PyStringRef, _bases: PyObjectRef, vm: &VirtualMachine) -> PyDictRef { + fn prepare(_name: PyStrRef, _bases: PyObjectRef, vm: &VirtualMachine) -> PyDictRef { vm.ctx.new_dict() } #[pymethod(magic)] - fn getattribute(zelf: PyRef, name_ref: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(zelf: PyRef, name_ref: PyStrRef, vm: &VirtualMachine) -> PyResult { let name = name_ref.borrow_value(); vm_trace!("type.__getattribute__({:?}, {:?})", zelf, name); let mcl = zelf.lease_class(); @@ -315,7 +315,7 @@ impl PyClass { #[pymethod(magic)] fn setattr( zelf: PyRef, - attr_name: PyStringRef, + attr_name: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { @@ -334,7 +334,7 @@ impl PyClass { } #[pymethod(magic)] - fn delattr(zelf: PyRef, attr_name: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn delattr(zelf: PyRef, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { if let Some(attr) = zelf.get_class_attr(attr_name.borrow_value()) { if let Some(ref descriptor) = attr.get_class_attr("__delete__") { return vm @@ -389,7 +389,7 @@ impl PyClass { })); } - let (name, bases, dict, kwargs): (PyStringRef, PyIterable, PyDictRef, KwArgs) = + let (name, bases, dict, kwargs): (PyStrRef, PyIterable, PyDictRef, KwArgs) = args.clone().bind(vm)?; let bases: Vec = bases.iter(vm)?.collect::, _>>()?; diff --git a/vm/src/py_io.rs b/vm/src/py_io.rs index a50b347e6..ac7f44087 100644 --- a/vm/src/py_io.rs +++ b/vm/src/py_io.rs @@ -1,6 +1,6 @@ use crate::exceptions::PyBaseExceptionRef; use crate::obj::objbytes::PyBytes; -use crate::obj::objstr::PyString; +use crate::obj::objstr::PyStr; use crate::pyobject::{BorrowValue, PyObjectRef, PyResult}; use crate::VirtualMachine; use std::{fmt, io}; @@ -41,7 +41,7 @@ pub fn file_readline(obj: &PyObjectRef, size: Option, vm: &VirtualMachine ) }; let ret = match_class!(match ret { - s @ PyString => { + s @ PyStr => { let sval = s.borrow_value(); if sval.is_empty() { return Err(eof_err()); diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index ad5cb86ab..57890dee1 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -214,7 +214,7 @@ impl PyContext { pub fn new_str(&self, s: S) -> PyObjectRef where - S: Into, + S: Into, { PyObject::new(s.into(), self.types.str_type.clone(), None) } @@ -288,8 +288,8 @@ impl PyContext { PyFuncDef::from(f.into_func()).build_function(self) } - pub(crate) fn new_stringref(&self, s: String) -> objstr::PyStringRef { - PyRef::new_ref(objstr::PyString::from(s), self.types.str_type.clone(), None) + pub(crate) fn new_stringref(&self, s: String) -> objstr::PyStrRef { + PyRef::new_ref(objstr::PyStr::from(s), self.types.str_type.clone(), None) } pub fn new_function_named(&self, f: F, name: String) -> PyFuncDef @@ -1222,10 +1222,10 @@ impl IntoPyObject for Either { /// /// ``` /// use rustpython_vm::VirtualMachine; -/// use rustpython_vm::obj::{objstr::PyStringRef, objint::PyIntRef}; +/// use rustpython_vm::obj::{objstr::PyStrRef, objint::PyIntRef}; /// use rustpython_vm::pyobject::Either; /// -/// fn do_something(arg: Either, vm: &VirtualMachine) { +/// fn do_something(arg: Either, vm: &VirtualMachine) { /// match arg { /// Either::A(int)=> { /// // do something with int diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index 1f43db2ad..152068cdc 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -9,7 +9,7 @@ use crate::obj::objiter; use crate::obj::objlist::PyList; use crate::obj::objsequence::{get_saturated_pos, PySliceableSequence, PySliceableSequenceMut}; use crate::obj::objslice::PySliceRef; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ BorrowValue, Either, IdProtocol, IntoPyObject, PyClassImpl, PyComparisonValue, PyIterable, @@ -479,7 +479,7 @@ impl PyArray { #[pyslot] fn tp_new( cls: PyClassRef, - spec: PyStringRef, + spec: PyStrRef, init: OptionalArg, vm: &VirtualMachine, ) -> PyResult { diff --git a/vm/src/stdlib/binascii.rs b/vm/src/stdlib/binascii.rs index fb32cbe7b..9a4ef7918 100644 --- a/vm/src/stdlib/binascii.rs +++ b/vm/src/stdlib/binascii.rs @@ -6,7 +6,7 @@ mod decl { use crate::function::OptionalArg; use crate::obj::objbytearray::{PyByteArray, PyByteArrayRef}; use crate::obj::objbytes::{PyBytes, PyBytesRef}; - use crate::obj::objstr::{PyString, PyStringRef}; + use crate::obj::objstr::{PyStr, PyStrRef}; use crate::pyobject::{BorrowValue, PyObjectRef, PyResult, TryFromObject, TypeProtocol}; use crate::vm::VirtualMachine; use crc::{crc32, Hasher32}; @@ -15,7 +15,7 @@ mod decl { enum SerializedData { Bytes(PyBytesRef), Buffer(PyByteArrayRef), - Ascii(PyStringRef), + Ascii(PyStrRef), } impl TryFromObject for SerializedData { @@ -23,7 +23,7 @@ mod decl { match_class!(match obj { b @ PyBytes => Ok(SerializedData::Bytes(b)), b @ PyByteArray => Ok(SerializedData::Buffer(b)), - a @ PyString => { + a @ PyStr => { if a.borrow_value().is_ascii() { Ok(SerializedData::Ascii(a)) } else { diff --git a/vm/src/stdlib/csv.rs b/vm/src/stdlib/csv.rs index c15895f79..58b5aae4e 100644 --- a/vm/src/stdlib/csv.rs +++ b/vm/src/stdlib/csv.rs @@ -5,7 +5,7 @@ use std::fmt::{self, Debug, Formatter}; use crate::common::cell::PyRwLock; use crate::function::PyFuncArgs; use crate::obj::objiter; -use crate::obj::objstr::{self, PyString}; +use crate::obj::objstr::{self, PyStr}; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ BorrowValue, IntoPyObject, PyClassImpl, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, @@ -77,7 +77,7 @@ fn into_strings(iterable: &PyIterable, vm: &VirtualMachine) -> PyRe .iter(vm)? .map(|py_obj_ref| { match_class!(match py_obj_ref? { - py_str @ PyString => Ok(py_str.borrow_value().trim().to_owned()), + py_str @ PyStr => Ok(py_str.borrow_value().trim().to_owned()), obj => { let msg = format!( "iterator should return strings, not {} (did you open the file in text mode?)", diff --git a/vm/src/stdlib/dis.rs b/vm/src/stdlib/dis.rs index 53c6129a6..4ce8c2f68 100644 --- a/vm/src/stdlib/dis.rs +++ b/vm/src/stdlib/dis.rs @@ -5,7 +5,7 @@ mod decl { use crate::bytecode::CodeFlags; use crate::obj::objcode::PyCodeRef; use crate::obj::objdict::PyDictRef; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, ItemProtocol, PyObjectRef, PyResult, TryFromObject}; use crate::vm::VirtualMachine; use rustpython_compiler::compile; @@ -15,7 +15,7 @@ mod decl { let co = if let Ok(co) = vm.get_attribute(obj.clone(), "__code__") { // Method or function: co - } else if let Ok(co_str) = PyStringRef::try_from_object(vm, obj.clone()) { + } else if let Ok(co_str) = PyStrRef::try_from_object(vm, obj.clone()) { // String: vm.compile( co_str.borrow_value(), diff --git a/vm/src/stdlib/hashlib.rs b/vm/src/stdlib/hashlib.rs index bb23e646d..f116fc354 100644 --- a/vm/src/stdlib/hashlib.rs +++ b/vm/src/stdlib/hashlib.rs @@ -5,7 +5,7 @@ mod hashlib { use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::function::{OptionalArg, PyFuncArgs}; use crate::obj::objbytes::{PyBytes, PyBytesRef}; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{BorrowValue, PyClassImpl, PyResult, PyValue}; use crate::vm::VirtualMachine; @@ -94,7 +94,7 @@ mod hashlib { #[pyfunction(name = "new")] fn hashlib_new( - name: PyStringRef, + name: PyStrRef, data: OptionalArg, vm: &VirtualMachine, ) -> PyResult { diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index 78fe259c1..42d543536 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -3,7 +3,7 @@ use crate::obj::objbytes::PyBytesRef; use crate::obj::objcode::PyCode; use crate::obj::objmodule::PyModuleRef; use crate::obj::objstr; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, ItemProtocol, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; @@ -49,11 +49,11 @@ fn _imp_extension_suffixes(vm: &VirtualMachine) -> PyResult { Ok(vm.ctx.new_list(vec![])) } -fn _imp_is_builtin(name: PyStringRef, vm: &VirtualMachine) -> bool { +fn _imp_is_builtin(name: PyStrRef, vm: &VirtualMachine) -> bool { vm.state.stdlib_inits.contains_key(name.borrow_value()) } -fn _imp_is_frozen(name: PyStringRef, vm: &VirtualMachine) -> bool { +fn _imp_is_frozen(name: PyStrRef, vm: &VirtualMachine) -> bool { vm.state.frozen.contains_key(name.borrow_value()) } @@ -76,7 +76,7 @@ fn _imp_exec_builtin(_mod: PyModuleRef) -> i32 { 0 } -fn _imp_get_frozen_object(name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn _imp_get_frozen_object(name: PyStrRef, vm: &VirtualMachine) -> PyResult { let name = name.borrow_value(); vm.state .frozen @@ -89,11 +89,11 @@ fn _imp_get_frozen_object(name: PyStringRef, vm: &VirtualMachine) -> PyResult PyResult { +fn _imp_init_frozen(name: PyStrRef, vm: &VirtualMachine) -> PyResult { import::import_frozen(vm, name.borrow_value()) } -fn _imp_is_frozen_package(name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn _imp_is_frozen_package(name: PyStrRef, vm: &VirtualMachine) -> PyResult { let name = name.borrow_value(); vm.state .frozen @@ -102,7 +102,7 @@ fn _imp_is_frozen_package(name: PyStringRef, vm: &VirtualMachine) -> PyResult, + encoding: Option, #[pyarg(positional_or_keyword, default = "None")] - errors: Option, + errors: Option, #[pyarg(positional_or_keyword, default = "None")] - newline: Option, + newline: Option, } impl TextIOWrapperArgs { @@ -645,14 +645,14 @@ mod _io { ) -> PyResult<()> { args.validate_newline(vm)?; - let mut encoding: Option = args.encoding.clone(); + let mut encoding: Option = args.encoding.clone(); let mut self_encoding = None; // TODO: Try os.device_encoding(fileno) if let (None, None) = (&encoding, &self_encoding) { // TODO: locale module self_encoding = Some("utf-8"); } if let Some(self_encoding) = self_encoding { - encoding = Some(PyString::from(self_encoding).into_ref(vm)); + encoding = Some(PyStr::from(self_encoding).into_ref(vm)); } else if let Some(ref encoding) = encoding { self_encoding = Some(encoding.borrow_value()) } else { @@ -741,7 +741,7 @@ mod _io { } #[pymethod] - fn write(instance: PyObjectRef, obj: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn write(instance: PyObjectRef, obj: PyStrRef, vm: &VirtualMachine) -> PyResult { use std::str::from_utf8; let buffered_writer_class = vm.try_class("_io", "BufferedWriter")?; @@ -798,7 +798,7 @@ mod _io { #[pyarg(positional_or_keyword, default = "None")] #[allow(dead_code)] // TODO: use this - newline: Option, + newline: Option, } #[pyclass(name = "StringIO", noattr)] @@ -864,7 +864,7 @@ mod _io { impl StringIORef { //write string to underlying vector #[pymethod] - fn write(self, data: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn write(self, data: PyStrRef, vm: &VirtualMachine) -> PyResult { let bytes = data.borrow_value().as_bytes(); match self.buffer(vm)?.write(bytes) { @@ -1112,7 +1112,7 @@ mod _io { #[pyfunction] fn open( file: PyObjectRef, - mode: OptionalArg, + mode: OptionalArg, opts: OpenArgs, vm: &VirtualMachine, ) -> PyResult { @@ -1136,11 +1136,11 @@ mod _io { #[pyarg(positional_or_keyword, default = "-1")] buffering: isize, #[pyarg(positional_or_keyword, default = "None")] - encoding: Option, + encoding: Option, #[pyarg(positional_or_keyword, default = "None")] - errors: Option, + errors: Option, #[pyarg(positional_or_keyword, default = "None")] - newline: Option, + newline: Option, #[pyarg(positional_or_keyword, default = "true")] closefd: bool, #[pyarg(positional_or_keyword, default = "None")] @@ -1407,7 +1407,7 @@ mod fileio { use crate::function::{OptionalArg, PyFuncArgs}; use crate::obj::objbytearray::PyByteArray; use crate::obj::objint; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ BorrowValue, BufferProtocol, Either, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, @@ -1451,9 +1451,9 @@ mod fileio { #[derive(FromArgs)] struct FileIOArgs { #[pyarg(positional_only)] - name: Either, + name: Either, #[pyarg(positional_or_keyword, default = "None")] - mode: Option, + mode: Option, #[pyarg(positional_or_keyword, default = "true")] closefd: bool, #[pyarg(positional_or_keyword, default = "None")] diff --git a/vm/src/stdlib/json.rs b/vm/src/stdlib/json.rs index f7a67b05c..21ebc828d 100644 --- a/vm/src/stdlib/json.rs +++ b/vm/src/stdlib/json.rs @@ -5,7 +5,7 @@ mod machinery; mod _json { use crate::function::PyFuncArgs; use crate::obj::objiter; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::obj::{objbool, objtype::PyClassRef}; use crate::pyobject::{ BorrowValue, IdProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, @@ -73,7 +73,7 @@ mod _json { fn parse( &self, s: &str, - pystr: PyStringRef, + pystr: PyStrRef, idx: usize, scan_once: PyObjectRef, vm: &VirtualMachine, @@ -196,12 +196,7 @@ mod _json { Some((ret, buf.len())) } - fn call( - zelf: &PyRef, - pystr: PyStringRef, - idx: isize, - vm: &VirtualMachine, - ) -> PyResult { + fn call(zelf: &PyRef, pystr: PyStrRef, idx: isize, vm: &VirtualMachine) -> PyResult { if idx < 0 { return Err(vm.new_value_error("idx cannot be negative".to_owned())); } @@ -224,7 +219,7 @@ mod _json { impl Callable for JsonScanner { fn call(zelf: &PyRef, args: PyFuncArgs, vm: &VirtualMachine) -> PyResult { - let (pystr, idx) = args.bind::<(PyStringRef, isize)>(vm)?; + let (pystr, idx) = args.bind::<(PyStrRef, isize)>(vm)?; JsonScanner::call(zelf, pystr, idx, vm) } } @@ -239,12 +234,12 @@ mod _json { } #[pyfunction] - fn encode_basestring(s: PyStringRef) -> String { + fn encode_basestring(s: PyStrRef) -> String { encode_string(s.borrow_value(), false) } #[pyfunction] - fn encode_basestring_ascii(s: PyStringRef) -> String { + fn encode_basestring_ascii(s: PyStrRef) -> String { encode_string(s.borrow_value(), true) } } diff --git a/vm/src/stdlib/keyword.rs b/vm/src/stdlib/keyword.rs index 56e77868e..a57a640c2 100644 --- a/vm/src/stdlib/keyword.rs +++ b/vm/src/stdlib/keyword.rs @@ -5,12 +5,12 @@ pub(crate) use decl::make_module; mod decl { use rustpython_parser::lexer; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; #[pyfunction] - fn iskeyword(s: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn iskeyword(s: PyStrRef, vm: &VirtualMachine) -> PyResult { let keywords = lexer::get_keywords(); let value = keywords.contains_key(s.borrow_value()); let value = vm.ctx.new_bool(value); diff --git a/vm/src/stdlib/msvcrt.rs b/vm/src/stdlib/msvcrt.rs index eacfaa51c..ce449994a 100644 --- a/vm/src/stdlib/msvcrt.rs +++ b/vm/src/stdlib/msvcrt.rs @@ -1,6 +1,6 @@ use super::os::errno_err; use crate::obj::objbytes::PyBytesRef; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, PyObjectRef, PyResult}; use crate::VirtualMachine; @@ -40,7 +40,7 @@ fn msvcrt_putch(b: PyBytesRef, vm: &VirtualMachine) -> PyResult<()> { unsafe { suppress_iph!(_putch(c.into())) }; Ok(()) } -fn msvcrt_putwch(s: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { +fn msvcrt_putwch(s: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { let c = s.borrow_value().chars().exactly_one().map_err(|_| { vm.new_type_error("putch() argument must be a string of length 1".to_owned()) })?; diff --git a/vm/src/stdlib/operator.rs b/vm/src/stdlib/operator.rs index 438d5d194..d09172bd0 100644 --- a/vm/src/stdlib/operator.rs +++ b/vm/src/stdlib/operator.rs @@ -1,6 +1,6 @@ use crate::byteslike::PyBytesLike; use crate::function::OptionalArg; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::{objiter, objtype}; use crate::pyobject::{BorrowValue, Either, PyObjectRef, PyResult, TypeProtocol}; use crate::VirtualMachine; @@ -70,8 +70,8 @@ fn timing_safe_cmp(a: &[u8], b: &[u8]) -> bool { } fn _operator_compare_digest( - a: Either, - b: Either, + a: Either, + b: Either, vm: &VirtualMachine, ) -> PyResult { let res = match (a, b) { diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 83a2688e1..8898b23ed 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -19,7 +19,7 @@ use crate::obj::objdict::PyDictRef; use crate::obj::objint::{PyInt, PyIntRef}; use crate::obj::objiter; use crate::obj::objset::PySet; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtuple::PyTupleRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ @@ -94,7 +94,7 @@ impl TryFromObject for PyPathLike { fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { let match1 = |obj: &PyObjectRef| { let pathlike = match_class!(match obj { - ref l @ PyString => PyPathLike { + ref l @ PyStr => PyPathLike { path: l.borrow_value().into(), mode: OutputMode::String, }, @@ -339,7 +339,7 @@ mod _os { } #[pyfunction] - fn error(message: OptionalArg, vm: &VirtualMachine) -> PyResult { + fn error(message: OptionalArg, vm: &VirtualMachine) -> PyResult { let msg = message.map_or("".to_owned(), |msg| msg.borrow_value().to_owned()); Err(vm.new_os_error(msg)) @@ -398,7 +398,7 @@ mod _os { } #[pyfunction] - fn mkdirs(path: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn mkdirs(path: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { fs::create_dir_all(path.borrow_value()).map_err(|err| err.into_pyexception(vm)) } @@ -422,8 +422,8 @@ mod _os { #[pyfunction] fn putenv( - key: Either, - value: Either, + key: Either, + value: Either, vm: &VirtualMachine, ) -> PyResult<()> { let key: &ffi::OsStr = match key { @@ -439,7 +439,7 @@ mod _os { } #[pyfunction] - fn unsetenv(key: Either, vm: &VirtualMachine) -> PyResult<()> { + fn unsetenv(key: Either, vm: &VirtualMachine) -> PyResult<()> { let key: &ffi::OsStr = match key { Either::A(ref s) => s.borrow_value().as_ref(), Either::B(ref b) => bytes_as_osstr(b.borrow_value(), vm)?, @@ -1478,7 +1478,7 @@ mod posix { } #[pyfunction] - fn system(command: PyStringRef) -> PyResult { + fn system(command: PyStrRef) -> PyResult { use std::ffi::CString; let rstr = command.borrow_value(); @@ -1508,7 +1508,7 @@ mod posix { #[pyfunction] fn execv( - path: PyStringRef, + path: PyStrRef, argv: Either, vm: &VirtualMachine, ) -> PyResult<()> { @@ -1856,7 +1856,7 @@ mod posix { target_os = "openbsd" ))] #[pyfunction] - fn initgroups(user_name: PyStringRef, gid: u32, vm: &VirtualMachine) -> PyResult<()> { + fn initgroups(user_name: PyStrRef, gid: u32, vm: &VirtualMachine) -> PyResult<()> { let user = ffi::CString::new(user_name.borrow_value()).unwrap(); let gid = Gid::from_raw(gid); unistd::initgroups(&user, gid).map_err(|err| err.into_pyexception(vm)) @@ -2506,7 +2506,7 @@ mod nt { #[cfg(target_env = "msvc")] #[pyfunction] fn execv( - path: PyStringRef, + path: PyStrRef, argv: Either, vm: &VirtualMachine, ) -> PyResult<()> { @@ -2589,7 +2589,7 @@ mod minor { } #[pyfunction] - pub(super) fn access(_path: PyStringRef, _mode: u8, vm: &VirtualMachine) -> PyResult { + pub(super) fn access(_path: PyStrRef, _mode: u8, vm: &VirtualMachine) -> PyResult { os_unimpl("os.access", vm) } diff --git a/vm/src/stdlib/pwd.rs b/vm/src/stdlib/pwd.rs index 9f791e667..090f562f7 100644 --- a/vm/src/stdlib/pwd.rs +++ b/vm/src/stdlib/pwd.rs @@ -1,6 +1,6 @@ use crate::exceptions::IntoPyException; use crate::obj::objint::PyIntRef; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, PyClassImpl, PyObjectRef, PyResult, PyStructSequence}; use crate::vm::VirtualMachine; use std::convert::TryFrom; @@ -46,7 +46,7 @@ impl From for Passwd { } } -fn pwd_getpwnam(name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn pwd_getpwnam(name: PyStrRef, vm: &VirtualMachine) -> PyResult { match User::from_name(name.borrow_value()).map_err(|err| err.into_pyexception(vm))? { Some(user) => Ok(Passwd::from(user) .into_struct_sequence(vm, vm.try_class("pwd", "struct_passwd")?)? diff --git a/vm/src/stdlib/pystruct.rs b/vm/src/stdlib/pystruct.rs index e93e4ef6c..0910b50e6 100644 --- a/vm/src/stdlib/pystruct.rs +++ b/vm/src/stdlib/pystruct.rs @@ -26,7 +26,7 @@ mod _struct { use crate::exceptions::PyBaseExceptionRef; use crate::function::Args; use crate::obj::{ - objbool::IntoPyBool, objbytes::PyBytesRef, objiter, objstr::PyString, objstr::PyStringRef, + objbool::IntoPyBool, objbytes::PyBytesRef, objiter, objstr::PyStr, objstr::PyStrRef, objtuple::PyTuple, objtype::PyClassRef, }; use crate::pyobject::{ @@ -90,7 +90,7 @@ mod _struct { impl FormatSpec { fn decode_and_parse( vm: &VirtualMachine, - fmt: &Either, + fmt: &Either, ) -> PyResult { let decoded_fmt = match fmt { Either::A(string) => string.borrow_value(), @@ -532,7 +532,7 @@ mod _struct { #[pyfunction] fn pack( - fmt: Either, + fmt: Either, args: Args, vm: &VirtualMachine, ) -> PyResult> { @@ -542,7 +542,7 @@ mod _struct { #[pyfunction] fn pack_into( - fmt: Either, + fmt: Either, buffer: PyRwBytesLike, offset: isize, args: Args, @@ -711,7 +711,7 @@ mod _struct { #[pyfunction] fn unpack( - fmt: Either, + fmt: Either, buffer: PyBytesLike, vm: &VirtualMachine, ) -> PyResult { @@ -775,7 +775,7 @@ mod _struct { #[pyfunction] fn unpack_from( - fmt: Either, + fmt: Either, args: UpdateFromArgs, vm: &VirtualMachine, ) -> PyResult { @@ -857,7 +857,7 @@ mod _struct { #[pyfunction] fn iter_unpack( - fmt: Either, + fmt: Either, buffer: PyBytesLike, vm: &VirtualMachine, ) -> PyResult { @@ -866,7 +866,7 @@ mod _struct { } #[pyfunction] - fn calcsize(fmt: Either, vm: &VirtualMachine) -> PyResult { + fn calcsize(fmt: Either, vm: &VirtualMachine) -> PyResult { let format_spec = FormatSpec::decode_and_parse(vm, &fmt)?; Ok(format_spec.size()) } @@ -876,7 +876,7 @@ mod _struct { #[derive(Debug)] struct PyStruct { spec: FormatSpec, - fmt_str: PyStringRef, + fmt_str: PyStrRef, } impl PyValue for PyStruct { @@ -890,20 +890,20 @@ mod _struct { #[pyslot] fn tp_new( cls: PyClassRef, - fmt: Either, + fmt: Either, vm: &VirtualMachine, ) -> PyResult> { let spec = FormatSpec::decode_and_parse(vm, &fmt)?; let fmt_str = match fmt { Either::A(s) => s, - Either::B(b) => PyString::from(std::str::from_utf8(b.borrow_value()).unwrap()) + Either::B(b) => PyStr::from(std::str::from_utf8(b.borrow_value()).unwrap()) .into_ref_with_type(vm, vm.ctx.types.str_type.clone())?, }; PyStruct { spec, fmt_str }.into_ref_with_type(vm, cls) } #[pyproperty] - fn format(&self) -> PyStringRef { + fn format(&self) -> PyStrRef { self.fmt_str.clone() } diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 900fed702..3bcb2b2f2 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -11,7 +11,7 @@ use std::ops::Range; use crate::function::{Args, OptionalArg}; use crate::obj::objint::{PyInt, PyIntRef}; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ BorrowValue, IntoPyObject, PyClassImpl, PyObjectRef, PyResult, PyValue, TryFromObject, @@ -73,7 +73,7 @@ impl PyValue for PyPattern { /// Inner data for a match object. #[pyclass(module = "re", name = "Match")] struct PyMatch { - haystack: PyStringRef, + haystack: PyStrRef, captures: Vec>>, } @@ -93,8 +93,8 @@ impl PyValue for PyMatch { // type PyMatchRef = PyRef; fn re_match( - pattern: PyStringRef, - string: PyStringRef, + pattern: PyStrRef, + string: PyStrRef, flags: OptionalArg, vm: &VirtualMachine, ) -> PyResult> { @@ -104,8 +104,8 @@ fn re_match( } fn re_search( - pattern: PyStringRef, - string: PyStringRef, + pattern: PyStrRef, + string: PyStrRef, flags: OptionalArg, vm: &VirtualMachine, ) -> PyResult> { @@ -115,9 +115,9 @@ fn re_search( } fn re_sub( - pattern: PyStringRef, - repl: PyStringRef, - string: PyStringRef, + pattern: PyStrRef, + repl: PyStrRef, + string: PyStrRef, count: OptionalArg, flags: OptionalArg, vm: &VirtualMachine, @@ -129,8 +129,8 @@ fn re_sub( } fn re_findall( - pattern: PyStringRef, - string: PyStringRef, + pattern: PyStrRef, + string: PyStrRef, flags: OptionalArg, vm: &VirtualMachine, ) -> PyResult { @@ -140,8 +140,8 @@ fn re_findall( } fn re_split( - pattern: PyStringRef, - string: PyStringRef, + pattern: PyStrRef, + string: PyStrRef, maxsplit: OptionalArg, flags: OptionalArg, vm: &VirtualMachine, @@ -151,12 +151,7 @@ fn re_split( do_split(vm, ®ex, string, maxsplit.into_option()) } -fn do_sub( - pattern: &PyPattern, - repl: PyStringRef, - search_text: PyStringRef, - limit: usize, -) -> String { +fn do_sub(pattern: &PyPattern, repl: PyStrRef, search_text: PyStrRef, limit: usize) -> String { let out = pattern.regex.replacen( search_text.borrow_value().as_bytes(), limit, @@ -165,7 +160,7 @@ fn do_sub( String::from_utf8_lossy(&out).into_owned() } -fn do_match(pattern: &PyPattern, search_text: PyStringRef) -> Option { +fn do_match(pattern: &PyPattern, search_text: PyStrRef) -> Option { // I really wish there was a better way to do this; I don't think there is let mut regex_text = r"\A".to_owned(); regex_text.push_str(pattern.regex.as_str()); @@ -175,14 +170,14 @@ fn do_match(pattern: &PyPattern, search_text: PyStringRef) -> Option { .map(|captures| create_match(search_text.clone(), captures)) } -fn do_search(regex: &PyPattern, search_text: PyStringRef) -> Option { +fn do_search(regex: &PyPattern, search_text: PyStrRef) -> Option { regex .regex .captures(search_text.borrow_value().as_bytes()) .map(|captures| create_match(search_text.clone(), captures)) } -fn do_findall(vm: &VirtualMachine, pattern: &PyPattern, search_text: PyStringRef) -> PyResult { +fn do_findall(vm: &VirtualMachine, pattern: &PyPattern, search_text: PyStrRef) -> PyResult { let out = pattern .regex .captures_iter(search_text.borrow_value().as_bytes()) @@ -218,7 +213,7 @@ fn do_findall(vm: &VirtualMachine, pattern: &PyPattern, search_text: PyStringRef fn do_split( vm: &VirtualMachine, pattern: &PyPattern, - search_text: PyStringRef, + search_text: PyStrRef, maxsplit: Option, ) -> PyResult { if maxsplit @@ -283,7 +278,7 @@ fn make_regex(vm: &VirtualMachine, pattern: &str, flags: PyRegexFlags) -> PyResu } /// Take a found regular expression and convert it to proper match object. -fn create_match(haystack: PyStringRef, captures: Captures) -> PyMatch { +fn create_match(haystack: PyStrRef, captures: Captures) -> PyMatch { let captures = captures .iter() .map(|opt| opt.map(|m| m.start()..m.end())) @@ -299,7 +294,7 @@ fn extract_flags(flags: OptionalArg) -> PyRegexFlags { } fn re_compile( - pattern: PyStringRef, + pattern: PyStrRef, flags: OptionalArg, vm: &VirtualMachine, ) -> PyResult { @@ -307,7 +302,7 @@ fn re_compile( make_regex(vm, pattern.borrow_value(), flags) } -fn re_escape(pattern: PyStringRef) -> String { +fn re_escape(pattern: PyStrRef) -> String { regex::escape(pattern.borrow_value()) } @@ -316,17 +311,17 @@ fn re_purge(_vm: &VirtualMachine) {} #[pyimpl] impl PyPattern { #[pymethod(name = "match")] - fn match_(&self, text: PyStringRef) -> Option { + fn match_(&self, text: PyStrRef) -> Option { do_match(self, text) } #[pymethod(name = "search")] - fn search(&self, text: PyStringRef) -> Option { + fn search(&self, text: PyStrRef) -> Option { do_search(self, text) } #[pymethod(name = "sub")] - fn sub(&self, repl: PyStringRef, text: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn sub(&self, repl: PyStrRef, text: PyStrRef, vm: &VirtualMachine) -> PyResult { let replaced_text = self.regex.replace_all( text.borrow_value().as_bytes(), repl.borrow_value().as_bytes(), @@ -336,7 +331,7 @@ impl PyPattern { } #[pymethod(name = "subn")] - fn subn(&self, repl: PyStringRef, text: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn subn(&self, repl: PyStrRef, text: PyStrRef, vm: &VirtualMachine) -> PyResult { self.sub(repl, text, vm) } @@ -348,7 +343,7 @@ impl PyPattern { #[pymethod] fn split( &self, - search_text: PyStringRef, + search_text: PyStrRef, maxsplit: OptionalArg, vm: &VirtualMachine, ) -> PyResult { @@ -356,7 +351,7 @@ impl PyPattern { } #[pymethod] - fn findall(&self, search_text: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn findall(&self, search_text: PyStrRef, vm: &VirtualMachine) -> PyResult { do_findall(vm, self, search_text) } } @@ -395,7 +390,7 @@ impl PyMatch { .ok_or_else(|| vm.new_index_error("No such group".to_owned()))?; Ok(capture.clone()) } - _s @ PyString => unimplemented!(), + _s @ PyStr => unimplemented!(), _ => Err(vm.new_index_error("No such group".to_owned())), }) } diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index 934fdc36e..c25e77930 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -15,7 +15,7 @@ use crate::exceptions::{IntoPyException, PyBaseExceptionRef}; use crate::function::{OptionalArg, PyFuncArgs}; use crate::obj::objbytearray::PyByteArrayRef; use crate::obj::objbytes::PyBytesRef; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtuple::PyTupleRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ @@ -428,7 +428,7 @@ impl io::Write for PySocketRef { } struct Address { - host: PyStringRef, + host: PyStrRef, port: u16, } @@ -445,9 +445,9 @@ impl TryFromObject for Address { if tuple.borrow_value().len() != 2 { Err(vm.new_type_error("Address tuple should have only 2 values".to_owned())) } else { - let host = PyStringRef::try_from_object(vm, tuple.borrow_value()[0].clone())?; + let host = PyStrRef::try_from_object(vm, tuple.borrow_value()[0].clone())?; let host = if host.borrow_value().is_empty() { - PyString::from("0.0.0.0").into_ref(vm) + PyStr::from("0.0.0.0").into_ref(vm) } else { host }; @@ -478,11 +478,11 @@ fn socket_gethostname(vm: &VirtualMachine) -> PyResult { } #[cfg(all(unix, not(target_os = "redox")))] -fn socket_sethostname(hostname: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { +fn socket_sethostname(hostname: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { sethostname(hostname.borrow_value()).map_err(|err| err.into_pyexception(vm)) } -fn socket_inet_aton(ip_string: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn socket_inet_aton(ip_string: PyStrRef, vm: &VirtualMachine) -> PyResult { ip_string .borrow_value() .parse::() @@ -501,9 +501,9 @@ fn socket_inet_ntoa(packed_ip: PyBytesRef, vm: &VirtualMachine) -> PyResult { #[derive(FromArgs)] struct GAIOptions { #[pyarg(positional_only)] - host: Option, + host: Option, #[pyarg(positional_only)] - port: Option>, + port: Option>, #[pyarg(positional_only, default = "0")] family: i32, @@ -557,7 +557,7 @@ fn socket_getaddrinfo(opts: GAIOptions, vm: &VirtualMachine) -> PyResult { #[cfg(not(target_os = "redox"))] fn socket_gethostbyaddr( - addr: PyStringRef, + addr: PyStrRef, vm: &VirtualMachine, ) -> PyResult<(String, PyObjectRef, PyObjectRef)> { // TODO: figure out how to do this properly @@ -577,10 +577,10 @@ fn socket_gethostbyaddr( } #[cfg(not(target_os = "redox"))] -fn socket_gethostbyname(name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn socket_gethostbyname(name: PyStrRef, vm: &VirtualMachine) -> PyResult { match socket_gethostbyaddr(name, vm) { Ok((_, _, hosts)) => { - let lst = vm.extract_elements::(&hosts)?; + let lst = vm.extract_elements::(&hosts)?; Ok(lst.get(0).unwrap().to_string()) } Err(_) => { @@ -593,7 +593,7 @@ fn socket_gethostbyname(name: PyStringRef, vm: &VirtualMachine) -> PyResult PyResult { +fn socket_inet_pton(af_inet: i32, ip_string: PyStrRef, vm: &VirtualMachine) -> PyResult { match af_inet { c::AF_INET => ip_string .borrow_value() @@ -643,7 +643,7 @@ fn socket_inet_ntop(af_inet: i32, packed_ip: PyBytesRef, vm: &VirtualMachine) -> } } -fn socket_getprotobyname(name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn socket_getprotobyname(name: PyStrRef, vm: &VirtualMachine) -> PyResult { use std::ffi::CString; let cstr = CString::new(name.borrow_value()) .map_err(|_| vm.new_value_error("embedded null character".to_owned()))?; diff --git a/vm/src/stdlib/ssl.rs b/vm/src/stdlib/ssl.rs index 426932d9a..4c9adbf14 100644 --- a/vm/src/stdlib/ssl.rs +++ b/vm/src/stdlib/ssl.rs @@ -4,7 +4,7 @@ use crate::common::cell::{PyRwLock, PyRwLockWriteGuard}; use crate::exceptions::{IntoPyException, PyBaseExceptionRef}; use crate::function::OptionalArg; use crate::obj::objbytearray::PyByteArrayRef; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::{objtype::PyClassRef, objweakref::PyWeak}; use crate::pyobject::{ BorrowValue, Either, IntoPyObject, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, @@ -112,7 +112,7 @@ fn obj2py(obj: &Asn1ObjectRef) -> PyNid { } #[cfg(windows)] -fn ssl_enum_certificates(store_name: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn ssl_enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult { use crate::obj::objset::PyFrozenSet; use schannel::{cert_context::ValidUses, cert_store::CertStore, RawPointer}; use winapi::um::wincrypt; @@ -194,7 +194,7 @@ fn ssl_rand_status() -> i32 { unsafe { sys::RAND_status() } } -fn ssl_rand_add(string: Either, entropy: f64) { +fn ssl_rand_add(string: Either, entropy: f64) { let f = |b: &[u8]| { for buf in b.chunks(libc::c_int::max_value() as usize) { unsafe { sys::RAND_add(buf.as_ptr() as *const _, buf.len() as _, entropy) } @@ -315,7 +315,7 @@ impl PySslContext { } #[pymethod] - fn set_ciphers(&self, cipherlist: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn set_ciphers(&self, cipherlist: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { let ciphers = cipherlist.borrow_value(); if ciphers.contains('\0') { return Err(vm.new_value_error("embedded null character".to_owned())); @@ -487,7 +487,7 @@ struct WrapSocketArgs { #[pyarg(positional_or_keyword)] server_side: bool, #[pyarg(positional_or_keyword, default = "None")] - server_hostname: Option, + server_hostname: Option, #[pyarg(keyword_only, default = "None")] owner: Option, #[pyarg(keyword_only, default = "None")] @@ -501,7 +501,7 @@ struct LoadVerifyLocationsArgs { #[pyarg(positional_or_keyword, default = "None")] capath: Option, #[pyarg(positional_or_keyword, default = "None")] - cadata: Option>, + cadata: Option>, } #[pyclass(module = "ssl", name = "_SSLSocket")] @@ -509,7 +509,7 @@ struct PySslSocket { ctx: PyRef, stream: PyRwLock>>, socket_type: SslServerOrClient, - server_hostname: Option, + server_hostname: Option, owner: PyRwLock>, } @@ -560,7 +560,7 @@ impl PySslSocket { self.ctx.clone() } #[pyproperty] - fn server_hostname(&self) -> Option { + fn server_hostname(&self) -> Option { self.server_hostname.clone() } diff --git a/vm/src/stdlib/string.rs b/vm/src/stdlib/string.rs index 951153f53..6a4db956b 100644 --- a/vm/src/stdlib/string.rs +++ b/vm/src/stdlib/string.rs @@ -12,7 +12,7 @@ mod _string { FieldName, FieldNamePart, FieldType, FormatPart, FormatString, FromTemplate, }; use crate::obj::objlist::PyList; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, IntoPyObject, PyObjectRef, PyResult}; use crate::vm::VirtualMachine; @@ -33,7 +33,7 @@ mod _string { } #[pyfunction] - fn formatter_parser(text: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn formatter_parser(text: PyStrRef, vm: &VirtualMachine) -> PyResult { let format_string = FormatString::from_str(text.borrow_value()).map_err(|e| e.into_pyexception(vm))?; @@ -71,7 +71,7 @@ mod _string { #[pyfunction] fn formatter_field_name_split( - text: PyStringRef, + text: PyStrRef, vm: &VirtualMachine, ) -> PyResult<(PyObjectRef, PyList)> { let field_name = diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 92bcd595b..fea85953e 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -4,7 +4,7 @@ pub(crate) use decl::make_module; mod decl { use std::fmt; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{BorrowValue, PyClassImpl, PyRef, PyResult, PyValue}; use crate::vm::VirtualMachine; @@ -15,9 +15,9 @@ mod decl { /// See docs: https://docs.python.org/3/library/symtable.html?highlight=symtable#symtable.symtable #[pyfunction] fn symtable( - source: PyStringRef, - filename: PyStringRef, - mode: PyStringRef, + source: PyStrRef, + filename: PyStrRef, + mode: PyStrRef, vm: &VirtualMachine, ) -> PyResult { let mode = mode @@ -106,7 +106,7 @@ mod decl { } #[pymethod(name = "lookup")] - fn lookup(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn lookup(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult { let name = name.borrow_value(); if let Some(symbol) = self.symtable.symbols.get(name) { Ok(PySymbol { diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index a3fb29567..3fb49e53e 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -2,7 +2,7 @@ use crate::exceptions::{self, IntoPyException}; use crate::function::{Args, KwArgs, OptionalArg, PyFuncArgs}; use crate::obj::objdict::PyDictRef; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtuple::PyTupleRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ @@ -311,7 +311,7 @@ impl PyLocal { } #[pymethod(magic)] - fn getattribute(zelf: PyRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn getattribute(zelf: PyRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult { let ldict = zelf.ldict(vm); if attr.borrow_value() == "__dict__" { Ok(ldict.into_object()) @@ -327,7 +327,7 @@ impl PyLocal { #[pymethod(magic)] fn setattr( zelf: PyRef, - attr: PyStringRef, + attr: PyStrRef, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()> { @@ -343,7 +343,7 @@ impl PyLocal { } #[pymethod(magic)] - fn delattr(zelf: PyRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn delattr(zelf: PyRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { if attr.borrow_value() == "__dict__" { Err(vm.new_attribute_error(format!( "{} attribute '__dict__' is read-only", diff --git a/vm/src/stdlib/time_module.rs b/vm/src/stdlib/time_module.rs index eebb04913..a79e770c3 100644 --- a/vm/src/stdlib/time_module.rs +++ b/vm/src/stdlib/time_module.rs @@ -8,7 +8,7 @@ use chrono::naive::{NaiveDate, NaiveDateTime, NaiveTime}; use chrono::{Datelike, Timelike}; use crate::function::OptionalArg; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtuple::PyTupleRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ @@ -144,11 +144,7 @@ fn time_ctime(secs: OptionalArg>, vm: &VirtualMachine) -> PyRes Ok(instant.format(&CFMT).to_string()) } -fn time_strftime( - format: PyStringRef, - t: OptionalArg, - vm: &VirtualMachine, -) -> PyResult { +fn time_strftime(format: PyStrRef, t: OptionalArg, vm: &VirtualMachine) -> PyResult { let default = chrono::offset::Local::now().naive_local(); let instant = match t { OptionalArg::Present(t) => t.to_date_time(vm)?, @@ -158,11 +154,7 @@ fn time_strftime( Ok(vm.ctx.new_str(formatted_time)) } -fn time_strptime( - string: PyStringRef, - format: OptionalArg, - vm: &VirtualMachine, -) -> PyResult { +fn time_strptime(string: PyStrRef, format: OptionalArg, vm: &VirtualMachine) -> PyResult { let format = match format { OptionalArg::Present(ref format) => format.borrow_value(), OptionalArg::Missing => "%a %b %H:%M:%S %Y", diff --git a/vm/src/stdlib/tokenize.rs b/vm/src/stdlib/tokenize.rs index 68951663b..674a71756 100644 --- a/vm/src/stdlib/tokenize.rs +++ b/vm/src/stdlib/tokenize.rs @@ -8,13 +8,13 @@ pub(crate) use decl::make_module; mod decl { use std::iter::FromIterator; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, PyResult}; use crate::vm::VirtualMachine; use rustpython_parser::lexer; #[pyfunction] - fn tokenize(s: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn tokenize(s: PyStrRef, vm: &VirtualMachine) -> PyResult { let source = s.borrow_value(); // TODO: implement generator when the time has come. diff --git a/vm/src/stdlib/unicodedata.rs b/vm/src/stdlib/unicodedata.rs index 961eabe14..3a2304692 100644 --- a/vm/src/stdlib/unicodedata.rs +++ b/vm/src/stdlib/unicodedata.rs @@ -3,7 +3,7 @@ */ use crate::function::OptionalArg; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{BorrowValue, PyClassImpl, PyObject, PyObjectRef, PyResult, PyValue}; use crate::vm::VirtualMachine; @@ -81,7 +81,7 @@ impl PyUCD { Age::of(c).map_or(false, |age| age.actual() <= self.unic_version) } - fn extract_char(&self, character: PyStringRef, vm: &VirtualMachine) -> PyResult> { + fn extract_char(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult> { let c = character .borrow_value() .chars() @@ -98,7 +98,7 @@ impl PyUCD { } #[pymethod] - fn category(&self, character: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn category(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult { Ok(self .extract_char(character, vm)? .map_or(GeneralCategory::Unassigned, GeneralCategory::of) @@ -107,7 +107,7 @@ impl PyUCD { } #[pymethod] - fn lookup(&self, name: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn lookup(&self, name: PyStrRef, vm: &VirtualMachine) -> PyResult { if let Some(character) = unicode_names2::character(name.borrow_value()) { if self.check_age(character) { return Ok(character.to_string()); @@ -119,7 +119,7 @@ impl PyUCD { #[pymethod] fn name( &self, - character: PyStringRef, + character: PyStrRef, default: OptionalArg, vm: &VirtualMachine, ) -> PyResult { @@ -139,7 +139,7 @@ impl PyUCD { } #[pymethod] - fn bidirectional(&self, character: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn bidirectional(&self, character: PyStrRef, vm: &VirtualMachine) -> PyResult { let bidi = match self.extract_char(character, vm)? { Some(c) => BidiClass::of(c).abbr_name(), None => "", @@ -148,12 +148,7 @@ impl PyUCD { } #[pymethod] - fn normalize( - &self, - form: PyStringRef, - unistr: PyStringRef, - vm: &VirtualMachine, - ) -> PyResult { + fn normalize(&self, form: PyStrRef, unistr: PyStrRef, vm: &VirtualMachine) -> PyResult { let text = unistr.borrow_value(); let normalized_text = match form.borrow_value() { "NFC" => text.nfc().collect::(), diff --git a/vm/src/stdlib/warnings.rs b/vm/src/stdlib/warnings.rs index ff56774e2..22316c6a0 100644 --- a/vm/src/stdlib/warnings.rs +++ b/vm/src/stdlib/warnings.rs @@ -3,7 +3,7 @@ pub(crate) use _warnings::make_module; #[pymodule] mod _warnings { use crate::function::OptionalArg; - use crate::obj::objstr::PyStringRef; + use crate::obj::objstr::PyStrRef; use crate::obj::objtype::{self, PyClassRef}; use crate::pyobject::{PyResult, TypeProtocol}; use crate::vm::VirtualMachine; @@ -11,7 +11,7 @@ mod _warnings { #[derive(FromArgs)] struct WarnArgs { #[pyarg(positional_only, optional = false)] - message: PyStringRef, + message: PyStrRef, #[pyarg(positional_or_keyword, optional = true)] category: OptionalArg, #[pyarg(positional_or_keyword, optional = true)] diff --git a/vm/src/stdlib/winapi.rs b/vm/src/stdlib/winapi.rs index 76918d237..3a8e2dfbe 100644 --- a/vm/src/stdlib/winapi.rs +++ b/vm/src/stdlib/winapi.rs @@ -12,7 +12,7 @@ use winapi::um::{ use super::os::errno_err; use crate::function::OptionalArg; use crate::obj::objdict::{PyDictRef, PyMapping}; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::pyobject::{BorrowValue, PyObjectRef, PyResult, PySequence, TryFromObject}; use crate::VirtualMachine; @@ -107,9 +107,9 @@ fn _winapi_GetFileType(h: usize, vm: &VirtualMachine) -> PyResult { #[derive(FromArgs)] struct CreateProcessArgs { #[pyarg(positional_only)] - name: Option, + name: Option, #[pyarg(positional_only)] - command_line: Option, + command_line: Option, #[pyarg(positional_only)] _proc_attrs: PyObjectRef, #[pyarg(positional_only)] @@ -121,7 +121,7 @@ struct CreateProcessArgs { #[pyarg(positional_only)] env_mapping: Option, #[pyarg(positional_only)] - current_dir: Option, + current_dir: Option, #[pyarg(positional_only)] startup_info: PyObjectRef, } @@ -169,7 +169,7 @@ fn _winapi_CreateProcess( .as_mut() .map_or_else(null_mut, |l| l.attrlist.as_mut_ptr() as _); - let wstr = |s: PyStringRef| { + let wstr = |s: PyStrRef| { if s.borrow_value().contains('\0') { Err(vm.new_value_error("embedded null character".to_owned())) } else { @@ -226,9 +226,9 @@ fn _winapi_CreateProcess( fn getenvironment(env: PyDictRef, vm: &VirtualMachine) -> PyResult> { let mut out = vec![]; for (k, v) in env { - let k = PyStringRef::try_from_object(vm, k)?; + let k = PyStrRef::try_from_object(vm, k)?; let k = k.borrow_value(); - let v = PyStringRef::try_from_object(vm, v)?; + let v = PyStrRef::try_from_object(vm, v)?; let v = v.borrow_value(); if k.contains('\0') || v.contains('\0') { return Err(vm.new_value_error("embedded null character".to_owned())); diff --git a/vm/src/stdlib/winreg.rs b/vm/src/stdlib/winreg.rs index 140d90fd7..121f009ff 100644 --- a/vm/src/stdlib/winreg.rs +++ b/vm/src/stdlib/winreg.rs @@ -2,7 +2,7 @@ use crate::common::cell::{PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard}; use crate::exceptions::IntoPyException; use crate::function::OptionalArg; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ BorrowValue, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, @@ -102,7 +102,7 @@ impl Hkey { fn winreg_OpenKey( key: Hkey, - subkey: Option, + subkey: Option, reserved: OptionalArg, access: OptionalArg, vm: &VirtualMachine, @@ -122,11 +122,7 @@ fn winreg_OpenKey( Ok(PyHKEY::new(key)) } -fn winreg_QueryValue( - key: Hkey, - subkey: Option, - vm: &VirtualMachine, -) -> PyResult { +fn winreg_QueryValue(key: Hkey, subkey: Option, vm: &VirtualMachine) -> PyResult { let subkey = subkey.as_ref().map_or("", |s| s.borrow_value()); key.with_key(|k| k.get_value(subkey)) .map_err(|e| e.into_pyexception(vm)) @@ -134,7 +130,7 @@ fn winreg_QueryValue( fn winreg_QueryValueEx( key: Hkey, - subkey: Option, + subkey: Option, vm: &VirtualMachine, ) -> PyResult<(PyObjectRef, usize)> { let subkey = subkey.as_ref().map_or("", |s| s.borrow_value()); diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index d408f29f8..6eee77c80 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -4,7 +4,7 @@ use std::{env, mem, path}; use crate::common::hash::{PyHash, PyUHash}; use crate::frame::FrameRef; use crate::function::{Args, OptionalArg, PyFuncArgs}; -use crate::obj::objstr::PyStringRef; +use crate::obj::objstr::PyStrRef; use crate::obj::objtype::PyClassRef; use crate::pyobject::{ IntoPyObject, ItemProtocol, PyClassImpl, PyContext, PyObjectRc, PyObjectRef, PyResult, @@ -213,7 +213,7 @@ fn sys_setrecursionlimit(recursion_limit: i32, vm: &VirtualMachine) -> PyResult< } // TODO implement string interning, this will be key for performance -fn sys_intern(value: PyStringRef) -> PyStringRef { +fn sys_intern(value: PyStrRef) -> PyStrRef { value } diff --git a/vm/src/types.rs b/vm/src/types.rs index 30e24110f..a6dc02f02 100644 --- a/vm/src/types.rs +++ b/vm/src/types.rs @@ -189,7 +189,7 @@ impl TypeZoo { set_iterator_type: create_type!(objset::PySetIterator), slice_type: create_type!(objslice::PySlice), staticmethod_type: create_type!(objstaticmethod::PyStaticMethod), - str_type: create_type!(objstr::PyString), + str_type: create_type!(objstr::PyStr), str_iterator_type: create_type!(objstr::PyStringIterator), str_reverseiterator_type: create_type!(objstr::PyStringReverseIterator), super_type: create_type!(objsuper::PySuper), diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 844d3661b..01b5e0225 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -33,7 +33,7 @@ use crate::obj::objiter; use crate::obj::objlist::PyList; use crate::obj::objmodule::{self, PyModule}; use crate::obj::objobject; -use crate::obj::objstr::{PyString, PyStringRef}; +use crate::obj::objstr::{PyStr, PyStrRef}; use crate::obj::objtuple::PyTuple; use crate::obj::objtype::{self, PyClassRef}; use crate::pyobject::{ @@ -708,12 +708,12 @@ impl VirtualMachine { } // Container of the virtual machine state: - pub fn to_str(&self, obj: &PyObjectRef) -> PyResult { + pub fn to_str(&self, obj: &PyObjectRef) -> PyResult { if obj.lease_class().is(&self.ctx.types.str_type) { Ok(obj.clone().downcast().unwrap()) } else { let s = self.call_method(&obj, "__str__", vec![])?; - PyStringRef::try_from_object(self, s) + PyStrRef::try_from_object(self, s) } } @@ -722,14 +722,14 @@ impl VirtualMachine { Ok(py_str_obj.borrow_value().to_owned()) } - pub fn to_repr(&self, obj: &PyObjectRef) -> PyResult { + pub fn to_repr(&self, obj: &PyObjectRef) -> PyResult { let repr = self.call_method(obj, "__repr__", vec![])?; TryFromObject::try_from_object(self, repr) } pub fn to_ascii(&self, obj: &PyObjectRef) -> PyResult { let repr = self.call_method(obj, "__repr__", vec![])?; - let repr: PyStringRef = TryFromObject::try_from_object(self, repr)?; + let repr: PyStrRef = TryFromObject::try_from_object(self, repr)?; let ascii = to_ascii(repr.borrow_value()); Ok(self.ctx.new_str(ascii)) } @@ -971,7 +971,7 @@ impl VirtualMachine { #[cfg_attr(feature = "flame-it", flame("VirtualMachine"))] pub fn get_attribute(&self, obj: PyObjectRef, attr_name: T) -> PyResult where - T: TryIntoRef, + T: TryIntoRef, { let attr_name = attr_name.try_into_ref(self)?; vm_trace!("vm.__getattribute__: {:?} {:?}", obj, attr_name); @@ -980,7 +980,7 @@ impl VirtualMachine { pub fn set_attr(&self, obj: &PyObjectRef, attr_name: K, attr_value: V) -> PyResult where - K: TryIntoRef, + K: TryIntoRef, V: Into, { let attr_name = attr_name.try_into_ref(self)?; @@ -1072,7 +1072,7 @@ impl VirtualMachine { }) } - pub fn generic_getattribute(&self, obj: PyObjectRef, name: PyStringRef) -> PyResult { + pub fn generic_getattribute(&self, obj: PyObjectRef, name: PyStrRef) -> PyResult { self.generic_getattribute_opt(obj.clone(), name.clone(), None)? .ok_or_else(|| self.new_attribute_error(format!("{} has no attribute '{}'", obj, name))) } @@ -1081,7 +1081,7 @@ impl VirtualMachine { pub fn generic_getattribute_opt( &self, obj: PyObjectRef, - name_str: PyStringRef, + name_str: PyStrRef, dict: Option, ) -> PyResult> { let name = name_str.borrow_value(); @@ -1174,8 +1174,8 @@ impl VirtualMachine { &self, func: &str, obj: PyObjectRef, - encoding: Option, - errors: Option, + encoding: Option, + errors: Option, ) -> PyResult { let codecsmodule = self.import("_codecs", &[], 0)?; let func = self.get_attribute(codecsmodule, func)?; @@ -1189,8 +1189,8 @@ impl VirtualMachine { pub fn decode( &self, obj: PyObjectRef, - encoding: Option, - errors: Option, + encoding: Option, + errors: Option, ) -> PyResult { self.call_codec_func("decode", obj, encoding, errors) } @@ -1198,8 +1198,8 @@ impl VirtualMachine { pub fn encode( &self, obj: PyObjectRef, - encoding: Option, - errors: Option, + encoding: Option, + errors: Option, ) -> PyResult { self.call_codec_func("encode", obj, encoding, errors) } @@ -1533,7 +1533,7 @@ impl VirtualMachine { pub fn __module_set_attr( &self, module: &PyObjectRef, - attr_name: impl TryIntoRef, + attr_name: impl TryIntoRef, attr_value: impl Into, ) -> PyResult<()> { let val = attr_value.into(); diff --git a/wasm/lib/src/browser_module.rs b/wasm/lib/src/browser_module.rs index e491edcce..fa18068d8 100644 --- a/wasm/lib/src/browser_module.rs +++ b/wasm/lib/src/browser_module.rs @@ -7,7 +7,7 @@ use wasm_bindgen_futures::{future_to_promise, JsFuture}; use rustpython_vm::common::rc::PyRc; use rustpython_vm::function::{OptionalArg, PyFuncArgs}; use rustpython_vm::import::import_file; -use rustpython_vm::obj::{objdict::PyDictRef, objstr::PyStringRef, objtype::PyClassRef}; +use rustpython_vm::obj::{objdict::PyDictRef, objstr::PyStrRef, objtype::PyClassRef}; use rustpython_vm::pyobject::{ BorrowValue, IntoPyObject, PyCallable, PyClassImpl, PyObject, PyObjectRef, PyRef, PyResult, PyValue, @@ -43,18 +43,18 @@ impl FetchResponseFormat { #[derive(FromArgs)] struct FetchArgs { #[pyarg(keyword_only, default = "None")] - response_format: Option, + response_format: Option, #[pyarg(keyword_only, default = "None")] - method: Option, + method: Option, #[pyarg(keyword_only, default = "None")] headers: Option, #[pyarg(keyword_only, default = "None")] body: Option, #[pyarg(keyword_only, default = "None")] - content_type: Option, + content_type: Option, } -fn browser_fetch(url: PyStringRef, args: FetchArgs, vm: &VirtualMachine) -> PyResult { +fn browser_fetch(url: PyStrRef, args: FetchArgs, vm: &VirtualMachine) -> PyResult { let FetchArgs { response_format, method, @@ -267,7 +267,7 @@ impl PyValue for Document { #[pyimpl] impl Document { #[pymethod] - fn query(&self, query: PyStringRef, vm: &VirtualMachine) -> PyResult { + fn query(&self, query: PyStrRef, vm: &VirtualMachine) -> PyResult { let elem = self .doc .query_selector(query.borrow_value()) @@ -295,7 +295,7 @@ impl Element { #[pymethod] fn get_attr( &self, - attr: PyStringRef, + attr: PyStrRef, default: OptionalArg, vm: &VirtualMachine, ) -> PyObjectRef { @@ -306,14 +306,14 @@ impl Element { } #[pymethod] - fn set_attr(&self, attr: PyStringRef, value: PyStringRef, vm: &VirtualMachine) -> PyResult<()> { + fn set_attr(&self, attr: PyStrRef, value: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { self.elem .set_attribute(attr.borrow_value(), value.borrow_value()) .map_err(|err| convert::js_py_typeerror(vm, err)) } } -fn browser_load_module(module: PyStringRef, path: PyStringRef, vm: &VirtualMachine) -> PyResult { +fn browser_load_module(module: PyStrRef, path: PyStrRef, vm: &VirtualMachine) -> PyResult { let weak_vm = weak_vm(vm); let mut opts = web_sys::RequestInit::new(); diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index 84d25bd88..89ed04940 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -2,7 +2,7 @@ use js_sys::{Array, Object, Reflect}; use rustpython_vm::common::rc::PyRc; use rustpython_vm::exceptions::PyBaseExceptionRef; use rustpython_vm::function::Args; -use rustpython_vm::obj::{objfloat::PyFloatRef, objstr::PyStringRef, objtype::PyClassRef}; +use rustpython_vm::obj::{objfloat::PyFloatRef, objstr::PyStrRef, objtype::PyClassRef}; use rustpython_vm::pyobject::{ BorrowValue, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, }; @@ -48,13 +48,13 @@ impl PyValue for PyJsValue { } enum JsProperty { - Str(PyStringRef), + Str(PyStrRef), Js(PyJsValueRef), } impl TryFromObject for JsProperty { fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { - PyStringRef::try_from_object(vm, obj.clone()) + PyStrRef::try_from_object(vm, obj.clone()) .map(JsProperty::Str) .or_else(|_| PyJsValueRef::try_from_object(vm, obj).map(JsProperty::Js)) } @@ -89,7 +89,7 @@ impl PyJsValue { } #[pymethod] - fn new_from_str(&self, s: PyStringRef) -> PyJsValue { + fn new_from_str(&self, s: PyStrRef) -> PyJsValue { PyJsValue::new(s.borrow_value()) } diff --git a/wasm/lib/src/wasm_builtins.rs b/wasm/lib/src/wasm_builtins.rs index b428ab186..fffbb3efb 100644 --- a/wasm/lib/src/wasm_builtins.rs +++ b/wasm/lib/src/wasm_builtins.rs @@ -6,7 +6,7 @@ use web_sys::{self, console}; -use rustpython_vm::obj::objstr::PyStringRef; +use rustpython_vm::obj::objstr::PyStrRef; use rustpython_vm::pyobject::{BorrowValue, PyObjectRef, PyResult}; use rustpython_vm::VirtualMachine; @@ -25,7 +25,7 @@ pub fn make_stdout_object( ) -> PyObjectRef { let ctx = &vm.ctx; let write_method = ctx.new_method( - move |_self: PyObjectRef, data: PyStringRef, vm: &VirtualMachine| -> PyResult<()> { + move |_self: PyObjectRef, data: PyStrRef, vm: &VirtualMachine| -> PyResult<()> { write_f(data.borrow_value(), vm) }, );