Skip to content

Commit 8172f3b

Browse files
committed
Fix CI
1 parent 8245b55 commit 8172f3b

File tree

7 files changed

+47
-45
lines changed

7 files changed

+47
-45
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115
- uses: actions-rs/cargo@v1
116116
with:
117117
command: test
118-
args: --no-default-features --features rand --workspace --exclude benchmark
118+
args: --no-default-features --features rand --workspace --exclude benchmark --exclude python
119119

120120
build-benchmark:
121121
name: Build benchmark
@@ -150,7 +150,7 @@ jobs:
150150
- uses: actions-rs/cargo@v1
151151
with:
152152
command: build
153-
args: --target aarch64-unknown-linux-gnu --all-features --workspace --exclude benchmark
153+
args: --target aarch64-unknown-linux-gnu --all-features --workspace --exclude benchmark --exclude python
154154

155155
fmt:
156156
name: Rustfmt

python/src/convert.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use pyo3::{
1111
FromPyObject, PyAny, PyErr, PyObject,
1212
};
1313
use std::os::raw::{c_double, c_longlong};
14+
use std::str::FromStr;
1415

1516
use crate::types::*;
1617
use dashu_base::{ConversionError, ParseError};
@@ -42,7 +43,7 @@ pub fn conversion_error_to_py(error: ConversionError) -> PyErr {
4243
ConversionError::LossOfPrecision => "precision loss happened during converison",
4344
};
4445

45-
PyValueError::new_err(expl).into()
46+
PyValueError::new_err(expl)
4647
}
4748

4849
pub fn parse_error_to_py(error: ParseError) -> PyErr {
@@ -55,7 +56,7 @@ pub fn parse_error_to_py(error: ParseError) -> PyErr {
5556
}
5657
};
5758

58-
PySyntaxError::new_err(expl).into()
59+
PySyntaxError::new_err(expl)
5960
}
6061

6162
/// Conversion from python integer object to rust int, without type checking.
@@ -133,7 +134,7 @@ pub fn parse_to_dbig(ob: &PyAny) -> PyResult<DBig> {
133134
// produce string in scientific notation. It will not produce many zeros when the
134135
// exponent is large.
135136
let s = ob.str()?;
136-
Ok(DBig::from_str_native(s.to_str()?).map_err(parse_error_to_py)?)
137+
DBig::from_str(s.to_str()?).map_err(parse_error_to_py)
137138
}
138139

139140
/// Conversion from fractions.Fraction object to RBig instance, without type checking.

python/src/float.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::hash_map::DefaultHasher;
22
use std::hash::Hasher;
3+
use std::str::FromStr;
34

45
use dashu_float::DBig;
56
use num_order::NumHash;
@@ -11,9 +12,9 @@ use crate::{
1112
types::{DPy, FPy, IPy},
1213
};
1314

14-
const ERRMSG_FBIG_WRONG_SRC_TYPE: &'static str =
15+
const ERRMSG_FBIG_WRONG_SRC_TYPE: &str =
1516
"only floats or strings can be used to construct an FBig instance";
16-
const ERRMSG_DBIG_WRONG_SRC_TYPE: &'static str =
17+
const ERRMSG_DBIG_WRONG_SRC_TYPE: &str =
1718
"only Decimal instances or strings can be used to construct a DBig instance";
1819

1920
#[pymethods]
@@ -27,7 +28,7 @@ impl FPy {
2728
Ok(FPy(f))
2829
} else if let Ok(s) = ob.extract() {
2930
// create from string
30-
let f = FBig::from_str_native(s);
31+
let f = FBig::from_str(s);
3132
Ok(FPy(f.map_err(parse_error_to_py)?))
3233
} else if let Ok(obj) = <PyRef<Self> as FromPyObject>::extract(ob) {
3334
Ok(FPy(obj.0.clone()))
@@ -71,7 +72,7 @@ impl DPy {
7172
Ok(DPy(parse_to_dbig(ob)?))
7273
} else if let Ok(s) = ob.extract() {
7374
// create from string
74-
let d = DBig::from_str_native(s);
75+
let d = DBig::from_str(s);
7576
Ok(DPy(d.map_err(parse_error_to_py)?))
7677
} else if let Ok(obj) = <PyRef<Self> as FromPyObject>::extract(ob) {
7778
Ok(DPy(obj.0.clone()))

python/src/int.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ use num_order::NumHash;
2323
type FBig = dashu_float::FBig;
2424

2525
// error messages
26-
const ERRMSG_LENGTH_TOO_LARGE: &'static str = "the integer has too many bits for indexing";
27-
const ERRMSG_STEPSIZE_TOO_LARGE: &'static str =
26+
const ERRMSG_LENGTH_TOO_LARGE: &str = "the integer has too many bits for indexing";
27+
const ERRMSG_STEPSIZE_TOO_LARGE: &str =
2828
"bit slicing with step size larger than 1 is not supported yet";
29-
const ERRMSG_UBIG_WRONG_SRC_TYPE: &'static str =
29+
const ERRMSG_UBIG_WRONG_SRC_TYPE: &str =
3030
"only integers or strings can be used to construct a UBig instance";
31-
const ERRMSG_IBIG_WRONG_SRC_TYPE: &'static str =
31+
const ERRMSG_IBIG_WRONG_SRC_TYPE: &str =
3232
"only integers or strings can be used to construct an IBig instance";
33-
const ERRMSG_FROM_WORDS_WRONG_TYPE: &'static str =
33+
const ERRMSG_FROM_WORDS_WRONG_TYPE: &str =
3434
"only list of integers or Words instance can be used in UBig.from_words()";
35-
const ERRMSG_WRONG_ENDIANNESS: &'static str = "byteorder must be either 'little' or 'big'";
36-
const ERRMSG_NEGATIVE_TO_UNSIGNED: &'static str = "can't convert negative int to unsigned";
37-
const ERRMSG_INT_WITH_RADIX: &'static str = "can't convert non-string with explicit base";
38-
const ERRMSG_WRONG_INDEX_TYPE: &'static str = "indices must be integers or slices";
39-
const ERRMSG_UBIG_BITS_OOR: &'static str = "bits index out of range";
40-
const ERRMSG_BITOPS_TYPE: &'static str = "bit operations are only defined between integers";
35+
const ERRMSG_WRONG_ENDIANNESS: &str = "byteorder must be either 'little' or 'big'";
36+
const ERRMSG_NEGATIVE_TO_UNSIGNED: &str = "can't convert negative int to unsigned";
37+
const ERRMSG_INT_WITH_RADIX: &str = "can't convert non-string with explicit base";
38+
const ERRMSG_WRONG_INDEX_TYPE: &str = "indices must be integers or slices";
39+
const ERRMSG_UBIG_BITS_OOR: &str = "bits index out of range";
40+
const ERRMSG_BITOPS_TYPE: &str = "bit operations are only defined between integers";
4141

4242
macro_rules! impl_binops {
4343
($ty_variant:ident, $py_method:ident, $rs_method:ident) => {
@@ -373,7 +373,7 @@ impl UPy {
373373
}
374374
/// Convert the integer to bytes, like int.to_bytes().
375375
fn to_bytes(&self, byteorder: Option<&str>, py: Python) -> PyResult<PyObject> {
376-
let byteorder = byteorder.unwrap_or(&"little");
376+
let byteorder = byteorder.unwrap_or("little");
377377
let bytes = match byteorder {
378378
"little" => PyBytes::new(py, &self.0.to_le_bytes()),
379379
"big" => PyBytes::new(py, &self.0.to_be_bytes()),
@@ -386,7 +386,7 @@ impl UPy {
386386
/// Create UBig from bytes, like int.from_bytes().
387387
#[staticmethod]
388388
fn from_bytes(bytes: &PyBytes, byteorder: Option<&str>) -> PyResult<Self> {
389-
let byteorder = byteorder.unwrap_or(&"little");
389+
let byteorder = byteorder.unwrap_or("little");
390390
let uint = match byteorder {
391391
"little" => UBig::from_le_bytes(bytes.as_bytes()),
392392
"big" => UBig::from_be_bytes(bytes.as_bytes()),
@@ -400,35 +400,35 @@ impl UPy {
400400
/********** operators **********/
401401
#[inline]
402402
fn __add__(&self, other: UniInput<'_>, py: Python) -> PyObject {
403-
upy_add(&self, other, py)
403+
upy_add(self, other, py)
404404
}
405405
#[inline]
406406
fn __radd__(&self, other: UniInput<'_>, py: Python) -> PyObject {
407-
upy_add(&self, other, py)
407+
upy_add(self, other, py)
408408
}
409409
#[inline]
410410
fn __sub__(&self, other: UniInput<'_>, py: Python) -> PyObject {
411-
upy_sub(&self, other, py)
411+
upy_sub(self, other, py)
412412
}
413413
#[inline]
414414
fn __rsub__(&self, other: UniInput<'_>, py: Python) -> PyObject {
415-
upy_rsub(other, &self, py)
415+
upy_rsub(other, self, py)
416416
}
417417
#[inline]
418418
fn __mul__(&self, other: UniInput<'_>, py: Python) -> PyObject {
419-
upy_mul(&self, other, py)
419+
upy_mul(self, other, py)
420420
}
421421
#[inline]
422422
fn __rmul__(&self, other: UniInput<'_>, py: Python) -> PyObject {
423-
upy_mul(&self, other, py)
423+
upy_mul(self, other, py)
424424
}
425425
#[inline]
426426
fn __truediv__(&self, other: UniInput<'_>, py: Python) -> PyObject {
427-
upy_div(&self, other, py)
427+
upy_div(self, other, py)
428428
}
429429
#[inline]
430430
fn __rtruediv__(&self, other: UniInput<'_>, py: Python) -> PyObject {
431-
upy_rdiv(other, &self, py)
431+
upy_rdiv(other, self, py)
432432
}
433433
#[inline]
434434
fn __mod__(&self, other: UniInput<'_>, py: Python) -> PyObject {
@@ -546,35 +546,35 @@ impl IPy {
546546
/********** operators **********/
547547
#[inline]
548548
fn __add__(&self, other: UniInput<'_>, py: Python) -> PyObject {
549-
ipy_add(&self, other, py)
549+
ipy_add(self, other, py)
550550
}
551551
#[inline]
552552
fn __radd__(&self, other: UniInput<'_>, py: Python) -> PyObject {
553-
ipy_add(&self, other, py)
553+
ipy_add(self, other, py)
554554
}
555555
#[inline]
556556
fn __sub__(&self, other: UniInput<'_>, py: Python) -> PyObject {
557-
ipy_sub(&self, other, py)
557+
ipy_sub(self, other, py)
558558
}
559559
#[inline]
560560
fn __rsub__(&self, other: UniInput<'_>, py: Python) -> PyObject {
561-
ipy_rsub(other, &self, py)
561+
ipy_rsub(other, self, py)
562562
}
563563
#[inline]
564564
fn __mul__(&self, other: UniInput<'_>, py: Python) -> PyObject {
565-
ipy_mul(&self, other, py)
565+
ipy_mul(self, other, py)
566566
}
567567
#[inline]
568568
fn __rmul__(&self, other: UniInput<'_>, py: Python) -> PyObject {
569-
ipy_mul(&self, other, py)
569+
ipy_mul(self, other, py)
570570
}
571571
#[inline]
572572
fn __truediv__(&self, other: UniInput<'_>, py: Python) -> PyObject {
573-
ipy_div(&self, other, py)
573+
ipy_div(self, other, py)
574574
}
575575
#[inline]
576576
fn __rtruediv__(&self, other: UniInput<'_>, py: Python) -> PyObject {
577-
ipy_rdiv(other, &self, py)
577+
ipy_rdiv(other, self, py)
578578
}
579579
#[inline]
580580
fn __mod__(&self, other: UniInput<'_>, py: Python) -> PyObject {
@@ -645,7 +645,7 @@ impl IPy {
645645
return Err(PyOverflowError::new_err(ERRMSG_NEGATIVE_TO_UNSIGNED));
646646
}
647647

648-
let byteorder = byteorder.unwrap_or(&"little");
648+
let byteorder = byteorder.unwrap_or("little");
649649
let bytes = match byteorder {
650650
"little" => PyBytes::new(py, &self.0.to_le_bytes()),
651651
"big" => PyBytes::new(py, &self.0.to_be_bytes()),
@@ -662,7 +662,7 @@ impl IPy {
662662
byteorder: Option<&str>,
663663
signed: Option<bool>,
664664
) -> PyResult<Self> {
665-
let byteorder = byteorder.unwrap_or(&"little");
665+
let byteorder = byteorder.unwrap_or("little");
666666
let signed = signed.unwrap_or(false);
667667
let int = match byteorder {
668668
"little" => match signed {

python/src/ratio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
types::RPy,
1111
};
1212

13-
const ERRMSG_RBIG_WRONG_SRC_TYPE: &'static str =
13+
const ERRMSG_RBIG_WRONG_SRC_TYPE: &str =
1414
"only Fraction instances or strings can be used to construct an RBig instance";
1515

1616
#[pymethods]

python/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ pub fn autos(s: &str, py: Python<'_>) -> PyResult<PyObject> {
5656
.map_err(parse_error_to_py)?
5757
.0)
5858
.into_py(py)
59-
} else if s.contains(&['p', 'P']) {
59+
} else if s.contains(['p', 'P']) {
6060
FPy(FBig::from_str(s).map_err(parse_error_to_py)?).into_py(py)
61-
} else if s.contains('.') || (!s.contains("0x") && s.contains(&['e', 'E'])) {
61+
} else if s.contains('.') || (!s.contains("0x") && s.contains(['e', 'E'])) {
6262
DPy(DBig::from_str(s).map_err(parse_error_to_py)?).into_py(py)
6363
} else if s.contains('-') {
6464
IPy(IBig::from_str_with_radix_prefix(s)

python/src/words.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use pyo3::{
88

99
use dashu_int::Word;
1010

11-
const ERRMSG_WORDS_WRONG_SRC_TYPE: &'static str =
11+
const ERRMSG_WORDS_WRONG_SRC_TYPE: &str =
1212
"only a list of word-length integers can be used to construct a Words instance";
1313
const ERRMSG_WORDS_OOR: &str = "words index out of range";
1414
const ERRMSG_WORDS_INVALID_INDEX: &str = "words indices must be integers or slices";
@@ -214,7 +214,7 @@ impl PyWords {
214214
fn __add__(&self, other: &PyAny) -> PyResult<Self> {
215215
let mut out = self.0.clone();
216216
if let Ok(list) = <Vec<Word> as FromPyObject>::extract(other) {
217-
out.extend(list.into_iter());
217+
out.extend(list);
218218
} else if let Ok(obj) = <PyRef<Self> as FromPyObject>::extract(other) {
219219
out.extend(obj.0.iter());
220220
} else {

0 commit comments

Comments
 (0)