Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a3fb40
Implement `random` module
malkoG Oct 26, 2019
908abef
Apply code review for test snippet
malkoG Dec 14, 2019
a20b6bf
Implement _random using the MT19937 algorithm
coolreader18 Feb 1, 2020
2fd9eb9
Add random.py from CPython 3.6
coolreader18 Feb 1, 2020
b40dcb7
Use random.Random in tempfile
coolreader18 Feb 1, 2020
a762bf8
Move gen_res53 to mersenne.rs
coolreader18 Feb 4, 2020
9abb258
Fix clippy warnings
coolreader18 Feb 4, 2020
c44f04b
Fallback exit code to 0 in case of overflow
arnavb Feb 4, 2020
4c49185
Have wasm/demo's "test" npm script build the demo in release mode
coolreader18 Feb 5, 2020
60037a2
Cache WASM dependencies
coolreader18 Feb 5, 2020
3960fb8
Merge pull request #1745 from arnavb/fix-exit-code
youknowone Feb 5, 2020
c435ba0
Merge pull request #1731 from RustPython/feature/implement-random
coolreader18 Feb 5, 2020
1bac582
&str::to_string -> &str::to_owned for literals
youknowone Feb 5, 2020
7d0d313
&str::to_string -> &str::to_owned for variables
youknowone Feb 5, 2020
78180ff
Merge pull request #1734 from youknowone/to-owned
youknowone Feb 5, 2020
9f5cd17
Add getset_descriptor
youknowone Feb 2, 2020
c3d5f6c
IntoPyGetterFunc, IntoPySetterFunc
youknowone Feb 2, 2020
ca55778
`&self` support for getter/setter
youknowone Feb 3, 2020
d1f9cb4
PySetResult and IntoPySetResult
youknowone Feb 3, 2020
226a2a6
VM polymorphism for getter and setter
youknowone Feb 3, 2020
23381b9
compatiibility for CPytthon descr_check
youknowone Feb 4, 2020
0aee78d
pyproperty generates PyGetSet instead of PyProperty
youknowone Feb 3, 2020
facabfe
Remove PropertyBuilder and add new_getset
youknowone Feb 5, 2020
58744df
Revert 08e66b5002f3a3a30db72b350b18c61d367ef1fc
youknowone Feb 1, 2020
c0b235e
cleanup property and get descriptor codes
youknowone Feb 2, 2020
429a276
Bump up to python 3.8 for Azure Pipelines
youknowone Jan 25, 2020
0f12db1
Merge pull request #1705 from youknowone/azure-38
youknowone Feb 5, 2020
e7ea486
Merge pull request #1738 from youknowone/getset
coolreader18 Feb 6, 2020
844b639
Fix SyntaxError initial value
youknowone Feb 5, 2020
6ddb690
Remove `_vm` parameter when it is not required
youknowone Feb 5, 2020
92cb58b
Remove `_vm` parameter - remove unused functions
youknowone Feb 6, 2020
7312e18
Merge pull request #1748 from youknowone/syntax-error
youknowone Feb 6, 2020
67f072d
Merge pull request #1749 from youknowone/_vm
youknowone Feb 6, 2020
f873c0e
Merge pull request #1746 from RustPython/coolreader18/wasm-test-produ…
coolreader18 Feb 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
&str::to_string -> &str::to_owned for variables
  • Loading branch information
youknowone committed Feb 5, 2020
commit 7d0d313aa573bada831fa3d8181df3fc34212393
36 changes: 18 additions & 18 deletions compiler/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ impl<O: OutputStream> Compiler<O> {
fn load_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::LoadName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}

fn store_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::StoreName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<O: OutputStream> Compiler<O> {
for name in names {
// import symbol from module:
self.emit(Instruction::ImportFrom {
name: name.symbol.to_string(),
name: name.symbol.to_owned(),
});

// Store module under proper name:
Expand Down Expand Up @@ -619,13 +619,13 @@ impl<O: OutputStream> Compiler<O> {
match &expression.node {
ast::ExpressionType::Identifier { name } => {
self.emit(Instruction::DeleteName {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::DeleteAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Subscript { a, b } => {
Expand Down Expand Up @@ -701,7 +701,7 @@ impl<O: OutputStream> Compiler<O> {
compile_varargs(&args.kwarg),
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();

Expand Down Expand Up @@ -909,7 +909,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(annotation) = &arg.annotation {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: arg.arg.to_string(),
value: arg.arg.to_owned(),
},
});
self.compile_expression(&annotation)?;
Expand Down Expand Up @@ -982,7 +982,7 @@ impl<O: OutputStream> Compiler<O> {
Varargs::None,
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();

Expand Down Expand Up @@ -1022,7 +1022,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});

Expand All @@ -1044,7 +1044,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.emit(Instruction::StoreSubscript);
Expand All @@ -1332,7 +1332,7 @@ impl<O: OutputStream> Compiler<O> {
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::StoreAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
Expand Down Expand Up @@ -1605,7 +1605,7 @@ impl<O: OutputStream> Compiler<O> {
Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::LoadAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
Compare { vals, ops } => {
Expand Down Expand Up @@ -1795,7 +1795,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(name) = &keyword.name {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.compile_expression(&keyword.value)?;
Expand Down Expand Up @@ -1858,7 +1858,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
Expand Down Expand Up @@ -1927,7 +1927,7 @@ impl<O: OutputStream> Compiler<O> {
ast::ComprehensionKind::Set { .. } => "<setcomp>",
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
}
.to_string();
.to_owned();

let line_number = self.get_source_line_number();
// Create magnificent function <listcomp>:
Expand Down Expand Up @@ -2099,7 +2099,7 @@ impl<O: OutputStream> Compiler<O> {
ast::StringGroup::Constant { value } => {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: value.to_string(),
value: value.to_owned(),
},
});
}
Expand Down Expand Up @@ -2266,7 +2266,7 @@ mod tests {
let mut compiler: Compiler = Default::default();
compiler.source_path = Some("source_path".to_owned());
compiler.push_new_code_object("<module>".to_owned());
let ast = parser::parse_program(&source.to_string()).unwrap();
let ast = parser::parse_program(source).unwrap();
let symbol_scope = make_symbol_table(&ast).unwrap();
compiler.compile_program(&ast, symbol_scope).unwrap();
compiler.pop_code_object()
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Symbol {
impl Symbol {
fn new(name: &str) -> Self {
Symbol {
name: name.to_string(),
name: name.to_owned(),
// table,
scope: SymbolScope::Unknown,
is_param: false,
Expand Down Expand Up @@ -304,7 +304,7 @@ impl SymbolTableBuilder {
}

fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
let table = SymbolTable::new(name.to_string(), typ, line_number);
let table = SymbolTable::new(name.to_owned(), typ, line_number);
self.tables.push(table);
}

Expand Down Expand Up @@ -793,7 +793,7 @@ impl SymbolTableBuilder {
// Insert symbol when required:
if !containing {
let symbol = Symbol::new(name);
table.symbols.insert(name.to_string(), symbol);
table.symbols.insert(name.to_owned(), symbol);
}

// Set proper flags on symbol:
Expand Down
2 changes: 1 addition & 1 deletion derive/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CompilationSource {
let module_name = if is_init {
parent.clone()
} else if parent.is_empty() {
stem.to_string()
stem.to_owned()
} else {
format!("{}.{}", parent, stem)
};
Expand Down
2 changes: 1 addition & 1 deletion derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn generate_class_def(
let meta = attr.parse_meta().expect("expected doc attr to be a meta");
if let Meta::NameValue(name_value) = meta {
if let Lit::Str(s) = name_value.lit {
let val = s.value().trim().to_string();
let val = s.value().trim().to_owned();
match doc {
Some(ref mut doc) => doc.push(val),
None => doc = Some(vec![val]),
Expand Down
2 changes: 1 addition & 1 deletion parser/src/fstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'a> FStringParser<'a> {
}))
} else {
spec = Some(Box::new(Constant {
value: spec_expression.to_string(),
value: spec_expression.to_owned(),
}))
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {

// Figure out if a -c option was given:
if let Some(command) = matches.value_of("c") {
run_command(&vm, scope, command.to_string())?;
run_command(&vm, scope, command.to_owned())?;
} else if let Some(module) = matches.value_of("m") {
run_module(&vm, module)?;
} else if let Some(filename) = matches.value_of("script") {
Expand Down Expand Up @@ -426,13 +426,13 @@ fn run_script(vm: &VirtualMachine, scope: Scope, script_file: &str) -> PyResult<
process::exit(1);
};

let dir = file_path.parent().unwrap().to_str().unwrap().to_string();
let dir = file_path.parent().unwrap().to_str().unwrap().to_owned();
let sys_path = vm.get_attribute(vm.sys_module.clone(), "path").unwrap();
vm.call_method(&sys_path, "insert", vec![vm.new_int(0), vm.new_str(dir)])?;

match util::read_file(&file_path) {
Ok(source) => {
_run_string(vm, scope, &source, file_path.to_str().unwrap().to_string())?;
_run_string(vm, scope, &source, file_path.to_str().unwrap().to_owned())?;
}
Err(err) => {
error!(
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn builtin_compile(args: CompileArgs, vm: &VirtualMachine) -> PyResult {
.parse::<compile::Mode>()
.map_err(|err| vm.new_value_error(err.to_string()))?;

vm.compile(&source, mode, args.filename.as_str().to_string())
vm.compile(&source, mode, args.filename.as_str().to_owned())
.map(|o| o.into_object())
.map_err(|err| vm.new_syntax_error(&err))
}
Expand Down Expand Up @@ -920,7 +920,7 @@ pub fn builtin_build_class_(
vm: &VirtualMachine,
) -> PyResult {
let name = qualified_name.as_str().split('.').next_back().unwrap();
let name_obj = vm.new_str(name.to_string());
let name_obj = vm.new_str(name.to_owned());

let mut metaclass = if let Some(metaclass) = kwargs.pop_kwarg("metaclass") {
PyClassRef::try_from_object(vm, metaclass)?
Expand Down
6 changes: 3 additions & 3 deletions vm/src/dictdatatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl DictKey for &PyObjectRef {
impl DictKey for &str {
fn do_hash(self, _vm: &VirtualMachine) -> PyResult<HashValue> {
// follow a similar route as the hashing of PyStringRef
let raw_hash = pyhash::hash_value(&self.to_string()).to_bigint().unwrap();
let raw_hash = pyhash::hash_value(&self.to_owned()).to_bigint().unwrap();
let raw_hash = pyhash::hash_bigint(&raw_hash);
let mut hasher = DefaultHasher::new();
raw_hash.hash(&mut hasher);
Expand All @@ -362,7 +362,7 @@ impl DictKey for &str {
Ok(py_str_value.as_str() == self)
} else {
// Fall back to PyString implementation.
let s = vm.new_str(self.to_string());
let s = vm.new_str(self.to_owned());
s.do_eq(vm, other_key)
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ mod tests {
fn check_hash_equivalence(text: &str) {
let vm: VirtualMachine = Default::default();
let value1 = text;
let value2 = vm.new_str(value1.to_string());
let value2 = vm.new_str(value1.to_owned());

let hash1 = value1.do_hash(&vm).expect("Hash should not fail.");
let hash2 = value2.do_hash(&vm).expect("Hash should not fail.");
Expand Down
2 changes: 1 addition & 1 deletion vm/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::vm::VirtualMachine;
use rustpython_compiler::compile;

pub fn eval(vm: &VirtualMachine, source: &str, scope: Scope, source_path: &str) -> PyResult {
match vm.compile(source, compile::Mode::Eval, source_path.to_string()) {
match vm.compile(source, compile::Mode::Eval, source_path.to_owned()) {
Ok(bytecode) => {
debug!("Code object: {:?}", bytecode);
vm.run_code_obj(bytecode, scope)
Expand Down
2 changes: 1 addition & 1 deletion vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn print_source_line<W: Write>(output: &mut W, filename: &str, lineno: usize) ->

/// Print exception occurrence location from traceback element
fn write_traceback_entry<W: Write>(output: &mut W, tb_entry: &PyTracebackRef) -> io::Result<()> {
let filename = tb_entry.frame.code.source_path.to_string();
let filename = tb_entry.frame.code.source_path.to_owned();
writeln!(
output,
r##" File "{}", line {}, in {}"##,
Expand Down
4 changes: 2 additions & 2 deletions vm/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ impl FormatString {
let arg_part = parts[0];

let format_spec = if parts.len() > 1 {
parts[1].to_string()
parts[1].to_owned()
} else {
String::new()
};
Expand All @@ -638,7 +638,7 @@ impl FormatString {
if let Ok(index) = arg_part.parse::<usize>() {
Ok(FormatPart::IndexSpec(index, format_spec))
} else {
Ok(FormatPart::KeywordSpec(arg_part.to_string(), format_spec))
Ok(FormatPart::KeywordSpec(arg_part.to_owned(), format_spec))
}
}

Expand Down
6 changes: 3 additions & 3 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ impl Frame {
.new_pyfunction(code_obj, scope, defaults, kw_only_defaults);

let name = qualified_name.as_str().split('.').next_back().unwrap();
vm.set_attr(&func_obj, "__name__", vm.new_str(name.to_string()))?;
vm.set_attr(&func_obj, "__name__", vm.new_str(name.to_owned()))?;
vm.set_attr(&func_obj, "__qualname__", qualified_name)?;
let module = self
.scope
Expand Down Expand Up @@ -1319,13 +1319,13 @@ impl Frame {
fn store_attr(&self, vm: &VirtualMachine, attr_name: &str) -> FrameResult {
let parent = self.pop_value();
let value = self.pop_value();
vm.set_attr(&parent, vm.new_str(attr_name.to_string()), value)?;
vm.set_attr(&parent, vm.new_str(attr_name.to_owned()), value)?;
Ok(None)
}

fn delete_attr(&self, vm: &VirtualMachine, attr_name: &str) -> FrameResult {
let parent = self.pop_value();
let name = vm.ctx.new_str(attr_name.to_string());
let name = vm.ctx.new_str(attr_name.to_owned());
vm.del_attr(&parent, name)?;
Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn import_codeobj(
set_file_attr: bool,
) -> PyResult {
let attrs = vm.ctx.new_dict();
attrs.set_item("__name__", vm.new_str(module_name.to_string()), vm)?;
attrs.set_item("__name__", vm.new_str(module_name.to_owned()), vm)?;
if set_file_attr {
attrs.set_item("__file__", vm.new_str(code_obj.source_path.to_owned()), vm)?;
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objbool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The class bool is a subclass of the class int, and cannot be subclassed.";
"__rand__" => context.new_method(bool_and),
"__xor__" => context.new_method(bool_xor),
"__rxor__" => context.new_method(bool_xor),
"__doc__" => context.new_str(bool_doc.to_string()),
"__doc__" => context.new_str(bool_doc.to_owned()),
});
}

Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objbyteinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl PyByteInner {
i @ PyMemoryView => Ok(i.try_value().unwrap()),
_ => Err(vm.new_index_error(
"can assign only bytes, buffers, or iterables of ints in range(0, 256)"
.to_string()
.to_owned()
)),
}),
};
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objdict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ macro_rules! dict_iterator {
let mut str_parts = vec![];
for (key, value) in zelf.dict.clone() {
let s = vm.to_repr(&$result_fn(vm, &key, &value))?;
str_parts.push(s.as_str().to_string());
str_parts.push(s.as_str().to_owned());
}
format!("{}([{}])", $class_name, str_parts.join(", "))
} else {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ macro_rules! impl_try_from_object_int {
vm.new_overflow_error(concat!(
"Int value cannot fit into Rust ",
stringify!($t)
).to_string())
).to_owned())
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl PyList {
let mut str_parts = Vec::with_capacity(zelf.elements.borrow().len());
for elem in zelf.elements.borrow().iter() {
let s = vm.to_repr(elem)?;
str_parts.push(s.as_str().to_string());
str_parts.push(s.as_str().to_owned());
}
format!("[{}]", str_parts.join(", "))
} else {
Expand Down
Loading