Skip to content

Commit b8d4ea7

Browse files
committed
fix more use of std
1 parent 4f218a5 commit b8d4ea7

File tree

17 files changed

+47
-46
lines changed

17 files changed

+47
-46
lines changed

src/byteswriter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl std::io::Write for PyBytesWriter<'_> {
212212
self.buffer.write_all(buf)
213213
}
214214

215-
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> {
215+
fn write_fmt(&mut self, args: core::fmt::Arguments<'_>) -> std::io::Result<()> {
216216
self.buffer.write_fmt(args)
217217
}
218218
}

src/conversions/bigdecimal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//! assert d + 1 == value
5050
//! ```
5151
52-
use std::str::FromStr;
52+
use core::str::FromStr;
5353

5454
#[cfg(feature = "experimental-inspect")]
5555
use crate::inspect::PyStaticExpr;
@@ -121,7 +121,7 @@ mod test_bigdecimal {
121121
use super::*;
122122
use crate::types::dict::PyDictMethods;
123123
use crate::types::PyDict;
124-
use std::ffi::CString;
124+
use alloc::ffi::CString;
125125

126126
use bigdecimal::{One, Zero};
127127
#[cfg(not(target_arch = "wasm32"))]

src/conversions/chrono.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn warn_truncated_leap_second(obj: &Bound<'_, PyAny>) {
635635

636636
#[cfg(not(Py_LIMITED_API))]
637637
fn py_date_to_naive_date(
638-
py_date: impl std::ops::Deref<Target = impl PyDateAccess>,
638+
py_date: impl core::ops::Deref<Target = impl PyDateAccess>,
639639
) -> PyResult<NaiveDate> {
640640
NaiveDate::from_ymd_opt(
641641
py_date.get_year(),
@@ -657,7 +657,7 @@ fn py_date_to_naive_date(py_date: &Bound<'_, PyAny>) -> PyResult<NaiveDate> {
657657

658658
#[cfg(not(Py_LIMITED_API))]
659659
fn py_time_to_naive_time(
660-
py_time: impl std::ops::Deref<Target = impl PyTimeAccess>,
660+
py_time: impl core::ops::Deref<Target = impl PyTimeAccess>,
661661
) -> PyResult<NaiveTime> {
662662
NaiveTime::from_hms_micro_opt(
663663
py_time.get_hour().into(),
@@ -715,7 +715,8 @@ fn py_datetime_to_datetime_with_timezone<Tz: TimeZone>(
715715
mod tests {
716716
use super::*;
717717
use crate::{test_utils::assert_warnings, types::PyTuple, BoundObject};
718-
use std::{cmp::Ordering, panic};
718+
use core::cmp::Ordering;
719+
use std::panic;
719720

720721
#[test]
721722
// Only Python>=3.9 has the zoneinfo package
@@ -1312,8 +1313,8 @@ mod tests {
13121313
use super::*;
13131314
use crate::test_utils::CatchWarnings;
13141315
use crate::types::IntoPyDict;
1316+
use alloc::ffi::CString;
13151317
use proptest::prelude::*;
1316-
use std::ffi::CString;
13171318

13181319
proptest! {
13191320

src/conversions/chrono_tz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ use crate::types::{any::PyAnyMethods, PyTzInfo};
4444
#[cfg(all(feature = "experimental-inspect", not(Py_3_9)))]
4545
use crate::PyTypeInfo;
4646
use crate::{intern, Borrowed, Bound, FromPyObject, PyAny, PyErr, Python};
47+
use alloc::borrow::Cow;
4748
use chrono_tz::Tz;
48-
use std::borrow::Cow;
49-
use std::str::FromStr;
49+
use core::str::FromStr;
5050

5151
impl<'py> IntoPyObject<'py> for Tz {
5252
type Target = PyTzInfo;

src/conversions/either.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ where
120120
// is not experimental, rather than the Rust type names.
121121
let err_msg = format!(
122122
"failed to convert the value to 'Union[{}, {}]'",
123-
std::any::type_name::<L>(),
124-
std::any::type_name::<R>()
123+
core::any::type_name::<L>(),
124+
core::any::type_name::<R>()
125125
);
126126
Err(PyTypeError::new_err(err_msg))
127127
}
@@ -135,7 +135,7 @@ where
135135

136136
#[cfg(test)]
137137
mod tests {
138-
use std::borrow::Cow;
138+
use alloc::borrow::Cow;
139139

140140
use crate::exceptions::PyTypeError;
141141
use crate::{IntoPyObject, Python};

src/conversions/eyre.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//! # Example: Using `eyre` in general
6464
//!
6565
//! Note that you don't need this feature to convert a [`PyErr`] into an [`eyre::Report`], because
66-
//! it can already convert anything that implements [`Error`](std::error::Error):
66+
//! it can already convert anything that implements [`Error`](core::error::Error):
6767
//!
6868
//! ```rust
6969
//! use pyo3::prelude::*;
@@ -137,8 +137,7 @@ mod tests {
137137
use eyre::{bail, eyre, Report, Result, WrapErr};
138138

139139
fn f() -> Result<()> {
140-
use std::io;
141-
bail!(io::Error::new(io::ErrorKind::PermissionDenied, "oh no!"));
140+
bail!("not int".parse::<u8>().unwrap_err())
142141
}
143142

144143
fn g() -> Result<()> {

src/conversions/hashbrown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
};
2929
#[cfg(feature = "experimental-inspect")]
3030
use crate::{type_hint_subscript, type_hint_union, PyTypeInfo};
31-
use std::hash;
31+
use core::hash;
3232

3333
impl<'py, K, V, H> IntoPyObject<'py> for hashbrown::HashMap<K, V, H>
3434
where

src/conversions/indexmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use crate::types::*;
9494
#[cfg(feature = "experimental-inspect")]
9595
use crate::{type_hint_subscript, PyTypeInfo};
9696
use crate::{Borrowed, Bound, FromPyObject, PyErr, Python};
97-
use std::hash;
97+
use core::hash;
9898

9999
impl<'py, K, V, H> IntoPyObject<'py> for indexmap::IndexMap<K, V, H>
100100
where

src/conversions/jiff.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ use crate::types::{PyDateAccess, PyDeltaAccess, PyTimeAccess};
5555
use crate::{intern, Borrowed, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, PyResult, Python};
5656
#[cfg(feature = "experimental-inspect")]
5757
use crate::{type_hint_identifier, PyTypeInfo};
58+
use alloc::borrow::Cow;
5859
use jiff::civil::{Date, DateTime, ISOWeekDate, Time};
5960
use jiff::tz::{Offset, TimeZone};
6061
use jiff::{SignedDuration, Span, Timestamp, Zoned};
6162
#[cfg(feature = "jiff-02")]
6263
use jiff_02 as jiff;
63-
use std::borrow::Cow;
6464

6565
fn datetime_to_pydatetime<'py>(
6666
py: Python<'py>,
@@ -604,8 +604,8 @@ impl From<jiff::Error> for PyErr {
604604
mod tests {
605605
use super::*;
606606
use crate::{types::PyTuple, BoundObject};
607+
use core::cmp::Ordering;
607608
use jiff::tz::Offset;
608-
use std::cmp::Ordering;
609609

610610
#[test]
611611
// Only Python>=3.9 has the zoneinfo package
@@ -860,7 +860,7 @@ mod tests {
860860
#[test]
861861
#[cfg(all(Py_3_9, not(windows)))]
862862
fn test_ambiguous_datetime_to_pyobject() {
863-
use std::str::FromStr;
863+
use core::str::FromStr;
864864
let dates = [
865865
Zoned::from_str("2020-10-24 23:00:00[UTC]").unwrap(),
866866
Zoned::from_str("2020-10-25 00:00:00[UTC]").unwrap(),
@@ -1069,22 +1069,22 @@ mod tests {
10691069
mod proptests {
10701070
use super::*;
10711071
use crate::types::IntoPyDict;
1072+
use alloc::ffi::CString;
10721073
use jiff::tz::TimeZoneTransition;
10731074
use jiff::SpanRelativeTo;
10741075
use proptest::prelude::*;
1075-
use std::ffi::CString;
10761076

10771077
// This is to skip the test if we are creating an invalid date, like February 31.
10781078
#[track_caller]
10791079
fn try_date(year: i16, month: i8, day: i8) -> Result<Date, TestCaseError> {
1080-
let location = std::panic::Location::caller();
1080+
let location = core::panic::Location::caller();
10811081
Date::new(year, month, day)
10821082
.map_err(|err| TestCaseError::reject(format!("{location}: {err:?}")))
10831083
}
10841084

10851085
#[track_caller]
10861086
fn try_time(hour: i8, min: i8, sec: i8, micro: i32) -> Result<Time, TestCaseError> {
1087-
let location = std::panic::Location::caller();
1087+
let location = core::panic::Location::caller();
10881088
Time::new(hour, min, sec, micro * 1000)
10891089
.map_err(|err| TestCaseError::reject(format!("{location}: {err:?}")))
10901090
}
@@ -1102,7 +1102,7 @@ mod tests {
11021102
) -> Result<Zoned, TestCaseError> {
11031103
let date = try_date(year, month, day)?;
11041104
let time = try_time(hour, min, sec, micro)?;
1105-
let location = std::panic::Location::caller();
1105+
let location = core::panic::Location::caller();
11061106
DateTime::from_parts(date, time)
11071107
.to_zoned(tz)
11081108
.map_err(|err| TestCaseError::reject(format!("{location}: {err:?}")))

src/conversions/num_bigint.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn int_to_u32_vec<const SIGNED: bool>(long: &Bound<'_, PyInt>) -> PyResult<Vec<u
267267
flags |= ffi::Py_ASNATIVEBYTES_UNSIGNED_BUFFER | ffi::Py_ASNATIVEBYTES_REJECT_NEGATIVE;
268268
}
269269
let n_bytes =
270-
unsafe { ffi::PyLong_AsNativeBytes(long.as_ptr().cast(), std::ptr::null_mut(), 0, flags) };
270+
unsafe { ffi::PyLong_AsNativeBytes(long.as_ptr().cast(), core::ptr::null_mut(), 0, flags) };
271271
let n_bytes_unsigned: usize = n_bytes
272272
.try_into()
273273
.map_err(|_| crate::PyErr::fetch(long.py()))?;
@@ -350,22 +350,22 @@ mod tests {
350350
fn rust_fib<T>() -> impl Iterator<Item = T>
351351
where
352352
T: From<u16>,
353-
for<'a> &'a T: std::ops::Add<Output = T>,
353+
for<'a> &'a T: core::ops::Add<Output = T>,
354354
{
355355
let mut f0: T = T::from(1);
356356
let mut f1: T = T::from(1);
357-
std::iter::from_fn(move || {
357+
core::iter::from_fn(move || {
358358
let f2 = &f0 + &f1;
359-
Some(std::mem::replace(&mut f0, std::mem::replace(&mut f1, f2)))
359+
Some(core::mem::replace(&mut f0, core::mem::replace(&mut f1, f2)))
360360
})
361361
}
362362

363363
fn python_fib(py: Python<'_>) -> impl Iterator<Item = Bound<'_, PyAny>> + '_ {
364364
let mut f0 = 1i32.into_pyobject(py).unwrap().into_any();
365365
let mut f1 = 1i32.into_pyobject(py).unwrap().into_any();
366-
std::iter::from_fn(move || {
366+
core::iter::from_fn(move || {
367367
let f2 = f0.call_method1("__add__", (&f1,)).unwrap();
368-
Some(std::mem::replace(&mut f0, std::mem::replace(&mut f1, f2)))
368+
Some(core::mem::replace(&mut f0, core::mem::replace(&mut f1, f2)))
369369
})
370370
}
371371

0 commit comments

Comments
 (0)