Skip to content

Commit 70c9625

Browse files
authored
Merge pull request RustPython#2379 from RustPython/coolreader18/rework-pystruct
Rework pystruct, again
2 parents 7417c37 + 75f9ea2 commit 70c9625

File tree

9 files changed

+310
-306
lines changed

9 files changed

+310
-306
lines changed

Cargo.lock

Lines changed: 32 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_struct.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,6 @@ def test_module_func(self):
723723
self.assertRaises(StopIteration, next, it)
724724
self.assertRaises(StopIteration, next, it)
725725

726-
# TODO: RUSTPYTHON
727-
@unittest.expectedFailure
728726
def test_half_float(self):
729727
# Little-endian examples from:
730728
# http://en.wikipedia.org/wiki/Half_precision_floating-point_format

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ hexf-parse = "0.1.0"
1818
cfg-if = "0.1"
1919
once_cell = "1.4.1"
2020
siphasher = "0.3"
21-
rand = "0.7.3"
21+
rand = "0.8"
2222
derive_more = "0.99.9"
2323
volatile = "0.3"

vm/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ num-traits = "0.2.8"
3434
num-integer = "0.1.41"
3535
num-rational = "0.3"
3636
num-iter = "0.1.39"
37-
rand = { version = "0.7", features = ["wasm-bindgen"] }
38-
rand_core = "0.5"
39-
getrandom = { version = "0.1", features = ["wasm-bindgen"] }
40-
mt19937 = "1.0"
37+
rand = "0.8"
38+
rand_core = "0.6"
39+
getrandom = { version = "0.2", features = ["js"] }
40+
mt19937 = "2.0"
4141
log = "0.4"
4242
rustpython-derive = { path = "../derive", version = "0.1.2" }
4343
rustpython-parser = { path = "../parser", optional = true, version = "0.1.2" }
@@ -47,10 +47,9 @@ rustpython-jit = { path = "../jit", optional = true, version = "0.1.2" }
4747
rustpython-pylib = { path = "pylib-crate", optional = true, version = "0.1.0" }
4848
serde = { version = "1.0.66", features = ["derive"] }
4949
serde_json = "1.0"
50-
byteorder = "1.2.6"
5150
regex = "1"
5251
rustc_version_runtime = "0.1.*"
53-
statrs = "0.12.0"
52+
puruspe = "0.1"
5453
caseless = "0.2.1"
5554
chrono = { version = "0.4", features = ["wasmbind"] }
5655
lexical-core = "0.7"
@@ -79,6 +78,7 @@ timsort = "0.1"
7978
thiserror = "1.0"
8079
atty = "0.2"
8180
static_assertions = "1.1"
81+
half = "1.6"
8282

8383
## unicode stuff
8484
unicode_names2 = "0.4"

vm/src/builtins/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ fn try_complex(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<(Compl
435435
if let Some(complex) = obj.payload_if_subclass::<PyComplex>(vm) {
436436
return Ok(Some((complex.value, true)));
437437
}
438-
if let Some(float) = float::try_float(obj, vm)? {
438+
if let Some(float) = float::try_float_opt(obj, vm)? {
439439
return Ok(Some((Complex64::new(float, 0.0), false)));
440440
}
441441
Ok(None)

vm/src/builtins/float.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl From<f64> for PyFloat {
5555
}
5656
}
5757

58-
pub(crate) fn try_float(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<f64>> {
58+
pub fn try_float_opt(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<f64>> {
5959
if let Some(float) = obj.payload_if_exact::<PyFloat>(vm) {
6060
return Ok(Some(float.value));
6161
}
@@ -76,6 +76,11 @@ pub(crate) fn try_float(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Opti
7676
Ok(None)
7777
}
7878

79+
pub fn try_float(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<f64> {
80+
try_float_opt(obj, vm)?
81+
.ok_or_else(|| vm.new_type_error(format!("must be real number, not {}", obj.class().name)))
82+
}
83+
7984
pub(crate) fn to_op_float(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<f64>> {
8085
let v = if let Some(float) = obj.payload_if_subclass::<PyFloat>(vm) {
8186
Some(float.value)
@@ -176,7 +181,7 @@ impl PyFloat {
176181
val
177182
};
178183

179-
if let Some(f) = try_float(&val, vm)? {
184+
if let Some(f) = try_float_opt(&val, vm)? {
180185
f
181186
} else if let Some(s) = val.payload_if_subclass::<PyStr>(vm) {
182187
float_ops::parse_str(s.borrow_value().trim()).ok_or_else(|| {
@@ -581,9 +586,7 @@ impl IntoPyFloat {
581586

582587
impl TryFromObject for IntoPyFloat {
583588
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
584-
let value = try_float(&obj, vm)?.ok_or_else(|| {
585-
vm.new_type_error(format!("must be real number, not {}", obj.class().name))
586-
})?;
589+
let value = try_float(&obj, vm)?;
587590
Ok(IntoPyFloat { value })
588591
}
589592
}

vm/src/builtins/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl PyMemoryView {
500500
.get_pos(i)
501501
.ok_or_else(|| vm.new_index_error("index out of range".to_owned()))?;
502502
let itemsize = zelf.options.itemsize;
503-
let data = zelf.format_spec.pack(&[value], vm)?;
503+
let data = zelf.format_spec.pack(vec![value], vm)?;
504504
zelf.obj_bytes_mut()[i..i + itemsize].copy_from_slice(&data);
505505
Ok(())
506506
}

vm/src/stdlib/math.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
use num_bigint::BigInt;
77
use num_traits::{One, Signed, Zero};
8-
use statrs::function::erf::{erf, erfc};
9-
use statrs::function::gamma::{gamma, ln_gamma};
8+
use puruspe::{erf, erfc, gamma, ln_gamma};
109

1110
use crate::builtins::float::{self, IntoPyFloat, PyFloatRef};
1211
use crate::builtins::int::{self, PyInt, PyIntRef};

0 commit comments

Comments
 (0)