Skip to content

Commit d1e111d

Browse files
authored
Merge pull request RustPython#2215 from youknowone/rename-str-types
Rename str types
2 parents c501103 + 651799c commit d1e111d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+444
-488
lines changed

src/shell/helper.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustpython_vm::obj::objstr::PyStringRef;
1+
use rustpython_vm::obj::objstr::PyStrRef;
22
use rustpython_vm::pyobject::{BorrowValue, PyIterable, PyResult, TryFromObject};
33
use rustpython_vm::scope::{NameProtocol, Scope};
44
use rustpython_vm::VirtualMachine;
@@ -59,16 +59,13 @@ impl<'vm> ShellHelper<'vm> {
5959
fn get_available_completions<'w>(
6060
&self,
6161
words: &'w [String],
62-
) -> Option<(
63-
&'w str,
64-
Box<dyn Iterator<Item = PyResult<PyStringRef>> + 'vm>,
65-
)> {
62+
) -> Option<(&'w str, Box<dyn Iterator<Item = PyResult<PyStrRef>> + 'vm>)> {
6663
// the very first word and then all the ones after the dot
6764
let (first, rest) = words.split_first().unwrap();
6865

6966
let str_iter_method = |obj, name| {
7067
let iter = self.vm.call_method(obj, name, vec![])?;
71-
PyIterable::<PyStringRef>::try_from_object(self.vm, iter)?.iter(self.vm)
68+
PyIterable::<PyStrRef>::try_from_object(self.vm, iter)?.iter(self.vm)
7269
};
7370

7471
if let Some((last, parents)) = rest.split_last() {

vm/src/pystr.rs renamed to vm/src/anystr.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::str::FromStr;
1111
#[derive(FromArgs)]
1212
pub struct SplitArgs<'a, T, S, E>
1313
where
14-
T: TryFromObject + PyCommonStringWrapper<S>,
15-
S: ?Sized + PyCommonString<'a, E>,
14+
T: TryFromObject + AnyStrWrapper<S>,
15+
S: ?Sized + AnyStr<'a, E>,
1616
E: Copy,
1717
{
1818
#[pyarg(positional_or_keyword, default = "None")]
@@ -25,8 +25,8 @@ where
2525

2626
impl<'a, T, S, E> SplitArgs<'a, T, S, E>
2727
where
28-
T: TryFromObject + PyCommonStringWrapper<S>,
29-
S: ?Sized + PyCommonString<'a, E>,
28+
T: TryFromObject + AnyStrWrapper<S>,
29+
S: ?Sized + AnyStr<'a, E>,
3030
E: Copy,
3131
{
3232
pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Option<T>, isize)> {
@@ -124,14 +124,14 @@ impl StringRange for std::ops::Range<usize> {
124124
}
125125
}
126126

127-
pub trait PyCommonStringWrapper<S>
127+
pub trait AnyStrWrapper<S>
128128
where
129129
S: ?Sized,
130130
{
131131
fn as_ref(&self) -> &S;
132132
}
133133

134-
pub trait PyCommonStringContainer<S>
134+
pub trait AnyStrContainer<S>
135135
where
136136
S: ?Sized,
137137
{
@@ -140,11 +140,11 @@ where
140140
fn push_str(&mut self, s: &S);
141141
}
142142

143-
pub trait PyCommonString<'s, E>
143+
pub trait AnyStr<'s, E>
144144
where
145145
E: Copy,
146146
Self: 's,
147-
Self::Container: PyCommonStringContainer<Self> + std::iter::Extend<E>,
147+
Self::Container: AnyStrContainer<Self> + std::iter::Extend<E>,
148148
Self::CharIter: 's + std::iter::Iterator<Item = char>,
149149
Self::ElementIter: 's + std::iter::Iterator<Item = E>,
150150
{
@@ -182,7 +182,7 @@ where
182182
splitw: SW,
183183
) -> PyResult<Vec<R>>
184184
where
185-
T: TryFromObject + PyCommonStringWrapper<Self>,
185+
T: TryFromObject + AnyStrWrapper<Self>,
186186
SP: Fn(&Self, &Self, &VirtualMachine) -> Vec<R>,
187187
SN: Fn(&Self, &Self, usize, &VirtualMachine) -> Vec<R>,
188188
SW: Fn(&Self, isize, &VirtualMachine) -> Vec<R>,
@@ -249,7 +249,7 @@ where
249249
func_default: FD,
250250
) -> &'a Self
251251
where
252-
S: PyCommonStringWrapper<Self>,
252+
S: AnyStrWrapper<Self>,
253253
FC: Fn(&'a Self, &Self) -> &'a Self,
254254
FD: Fn(&'a Self) -> &'a Self,
255255
{
@@ -312,7 +312,7 @@ where
312312

313313
fn py_join<'a>(
314314
&self,
315-
mut iter: PyIterator<'a, impl PyCommonStringWrapper<Self> + TryFromObject>,
315+
mut iter: PyIterator<'a, impl AnyStrWrapper<Self> + TryFromObject>,
316316
) -> PyResult<Self::Container> {
317317
let mut joined = if let Some(elem) = iter.next() {
318318
elem?.as_ref().to_container()

vm/src/builtins.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod decl {
2929
use crate::obj::objiter;
3030
use crate::obj::objlist::{PyList, SortOptions};
3131
use crate::obj::objsequence;
32-
use crate::obj::objstr::{PyString, PyStringRef};
32+
use crate::obj::objstr::{PyStr, PyStrRef};
3333
use crate::obj::objtype::{self, PyClassRef};
3434
use crate::pyobject::{
3535
BorrowValue, Either, IdProtocol, ItemProtocol, PyCallable, PyIterable, PyObjectRef,
@@ -108,11 +108,11 @@ mod decl {
108108
#[allow(dead_code)]
109109
struct CompileArgs {
110110
#[pyarg(positional_only, optional = false)]
111-
source: Either<PyStringRef, PyBytesRef>,
111+
source: Either<PyStrRef, PyBytesRef>,
112112
#[pyarg(positional_only, optional = false)]
113-
filename: PyStringRef,
113+
filename: PyStrRef,
114114
#[pyarg(positional_only, optional = false)]
115-
mode: PyStringRef,
115+
mode: PyStrRef,
116116
#[pyarg(positional_or_keyword, optional = true)]
117117
flags: OptionalArg<PyIntRef>,
118118
#[pyarg(positional_or_keyword, optional = true)]
@@ -162,7 +162,7 @@ mod decl {
162162
}
163163

164164
#[pyfunction]
165-
fn delattr(obj: PyObjectRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult<()> {
165+
fn delattr(obj: PyObjectRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult<()> {
166166
vm.del_attr(&obj, attr.into_object())
167167
}
168168

@@ -200,7 +200,7 @@ mod decl {
200200
#[cfg(feature = "rustpython-compiler")]
201201
#[pyfunction]
202202
fn eval(
203-
source: Either<PyStringRef, PyCodeRef>,
203+
source: Either<PyStrRef, PyCodeRef>,
204204
scope: ScopeArgs,
205205
vm: &VirtualMachine,
206206
) -> PyResult {
@@ -212,7 +212,7 @@ mod decl {
212212
#[cfg(feature = "rustpython-compiler")]
213213
#[pyfunction]
214214
fn exec(
215-
source: Either<PyStringRef, PyCodeRef>,
215+
source: Either<PyStrRef, PyCodeRef>,
216216
scope: ScopeArgs,
217217
vm: &VirtualMachine,
218218
) -> PyResult {
@@ -222,7 +222,7 @@ mod decl {
222222
#[cfg(feature = "rustpython-compiler")]
223223
fn run_code(
224224
vm: &VirtualMachine,
225-
source: Either<PyStringRef, PyCodeRef>,
225+
source: Either<PyStrRef, PyCodeRef>,
226226
scope: ScopeArgs,
227227
mode: compile::Mode,
228228
) -> PyResult {
@@ -272,12 +272,12 @@ mod decl {
272272
#[pyfunction]
273273
fn format(
274274
value: PyObjectRef,
275-
format_spec: OptionalArg<PyStringRef>,
275+
format_spec: OptionalArg<PyStrRef>,
276276
vm: &VirtualMachine,
277-
) -> PyResult<PyStringRef> {
277+
) -> PyResult<PyStrRef> {
278278
let format_spec = format_spec
279279
.into_option()
280-
.unwrap_or_else(|| PyString::from("").into_ref(vm));
280+
.unwrap_or_else(|| PyStr::from("").into_ref(vm));
281281

282282
vm.call_method(&value, "__format__", vec![format_spec.into_object()])?
283283
.downcast()
@@ -304,7 +304,7 @@ mod decl {
304304
#[pyfunction]
305305
fn getattr(
306306
obj: PyObjectRef,
307-
attr: PyStringRef,
307+
attr: PyStrRef,
308308
default: OptionalArg<PyObjectRef>,
309309
vm: &VirtualMachine,
310310
) -> PyResult {
@@ -322,7 +322,7 @@ mod decl {
322322
}
323323

324324
#[pyfunction]
325-
fn hasattr(obj: PyObjectRef, attr: PyStringRef, vm: &VirtualMachine) -> PyResult<bool> {
325+
fn hasattr(obj: PyObjectRef, attr: PyStrRef, vm: &VirtualMachine) -> PyResult<bool> {
326326
if let Err(ex) = vm.get_attribute(obj, attr) {
327327
catch_attr_exception(ex, false, vm)
328328
} else {
@@ -355,7 +355,7 @@ mod decl {
355355
}
356356

357357
#[pyfunction]
358-
fn input(prompt: OptionalArg<PyStringRef>, vm: &VirtualMachine) -> PyResult {
358+
fn input(prompt: OptionalArg<PyStrRef>, vm: &VirtualMachine) -> PyResult {
359359
let stdin = sysmodule::get_stdin(vm)?;
360360
let stdout = sysmodule::get_stdout(vm)?;
361361
let stderr = sysmodule::get_stderr(vm)?;
@@ -590,7 +590,7 @@ mod decl {
590590
}
591591

592592
#[pyfunction]
593-
fn ord(string: Either<PyBytesLike, PyStringRef>, vm: &VirtualMachine) -> PyResult<u32> {
593+
fn ord(string: Either<PyBytesLike, PyStrRef>, vm: &VirtualMachine) -> PyResult<u32> {
594594
match string {
595595
Either::A(bytes) => bytes.with_ref(|bytes| {
596596
let bytes_len = bytes.len();
@@ -670,9 +670,9 @@ mod decl {
670670
#[derive(Debug, Default, FromArgs)]
671671
pub struct PrintOptions {
672672
#[pyarg(keyword_only, default = "None")]
673-
sep: Option<PyStringRef>,
673+
sep: Option<PyStrRef>,
674674
#[pyarg(keyword_only, default = "None")]
675-
end: Option<PyStringRef>,
675+
end: Option<PyStrRef>,
676676
#[pyarg(keyword_only, default = "IntoPyBool::FALSE")]
677677
flush: IntoPyBool,
678678
#[pyarg(keyword_only, default = "None")]
@@ -685,11 +685,9 @@ mod decl {
685685
Some(f) => f,
686686
None => sysmodule::get_stdout(vm)?,
687687
};
688-
let write = |obj: PyStringRef| vm.call_method(&file, "write", vec![obj.into_object()]);
688+
let write = |obj: PyStrRef| vm.call_method(&file, "write", vec![obj.into_object()]);
689689

690-
let sep = options
691-
.sep
692-
.unwrap_or_else(|| PyString::from(" ").into_ref(vm));
690+
let sep = options.sep.unwrap_or_else(|| PyStr::from(" ").into_ref(vm));
693691

694692
let mut first = true;
695693
for object in objects {
@@ -704,7 +702,7 @@ mod decl {
704702

705703
let end = options
706704
.end
707-
.unwrap_or_else(|| PyString::from("\n").into_ref(vm));
705+
.unwrap_or_else(|| PyStr::from("\n").into_ref(vm));
708706
write(end)?;
709707

710708
if options.flush.to_bool() {
@@ -715,7 +713,7 @@ mod decl {
715713
}
716714

717715
#[pyfunction]
718-
fn repr(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStringRef> {
716+
fn repr(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
719717
vm.to_repr(&obj)
720718
}
721719

@@ -759,7 +757,7 @@ mod decl {
759757
#[pyfunction]
760758
fn setattr(
761759
obj: PyObjectRef,
762-
attr: PyStringRef,
760+
attr: PyStrRef,
763761
value: PyObjectRef,
764762
vm: &VirtualMachine,
765763
) -> PyResult<()> {
@@ -804,7 +802,7 @@ mod decl {
804802
#[pyfunction]
805803
pub fn __build_class__(
806804
function: PyFunctionRef,
807-
qualified_name: PyStringRef,
805+
qualified_name: PyStrRef,
808806
bases: Args<PyClassRef>,
809807
mut kwargs: KwArgs,
810808
vm: &VirtualMachine,

0 commit comments

Comments
 (0)