Skip to content

Commit 42e8b1d

Browse files
committed
import from alloc or core instead of std
1 parent 68dc3da commit 42e8b1d

112 files changed

Lines changed: 709 additions & 705 deletions

Some content is hidden

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

src/buffer.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
use crate::inspect::{type_hint_identifier, PyStaticExpr};
2323
use crate::{err, exceptions::PyBufferError, ffi, FromPyObject, PyAny, PyResult, Python};
2424
use crate::{Borrowed, Bound, PyErr};
25-
use std::ffi::{
25+
use core::ffi::{
2626
c_char, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, c_ulong, c_ulonglong,
2727
c_ushort, c_void,
2828
};
29-
use std::marker::{PhantomData, PhantomPinned};
30-
use std::pin::Pin;
31-
use std::ptr::NonNull;
32-
use std::{cell, mem, ptr, slice};
33-
use std::{ffi::CStr, fmt::Debug};
29+
use core::marker::{PhantomData, PhantomPinned};
30+
use core::pin::Pin;
31+
use core::ptr::NonNull;
32+
use core::{cell, mem, ptr, slice};
33+
use core::{ffi::CStr, fmt::Debug};
3434

3535
/// A typed form of [`PyUntypedBuffer`].
3636
#[repr(transparent)]
@@ -56,22 +56,22 @@ unsafe impl Send for PyUntypedBuffer {}
5656
unsafe impl Sync for PyUntypedBuffer {}
5757

5858
impl<T> Debug for PyBuffer<T> {
59-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6060
debug_buffer("PyBuffer", &self.0, f)
6161
}
6262
}
6363

6464
impl Debug for PyUntypedBuffer {
65-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6666
debug_buffer("PyUntypedBuffer", self, f)
6767
}
6868
}
6969

7070
fn debug_buffer(
7171
name: &str,
7272
b: &PyUntypedBuffer,
73-
f: &mut std::fmt::Formatter<'_>,
74-
) -> std::fmt::Result {
73+
f: &mut core::fmt::Formatter<'_>,
74+
) -> core::fmt::Result {
7575
let raw = b.raw();
7676
f.debug_struct(name)
7777
.field("buf", &raw.buf)
@@ -366,7 +366,7 @@ impl<T: Element> PyBuffer<T> {
366366
#[cfg(not(Py_3_11))]
367367
ptr::from_ref(self.raw()).cast_mut(),
368368
self.raw().len,
369-
fort as std::ffi::c_char,
369+
fort as core::ffi::c_char,
370370
)
371371
})
372372
}
@@ -401,7 +401,7 @@ impl<T: Element> PyBuffer<T> {
401401
#[cfg(not(Py_3_11))]
402402
ptr::from_ref(self.raw()).cast_mut(),
403403
self.raw().len,
404-
fort as std::ffi::c_char,
404+
fort as core::ffi::c_char,
405405
)
406406
})?;
407407
// set vector length to mark the now-initialized space as usable
@@ -463,13 +463,13 @@ impl<T: Element> PyBuffer<T> {
463463
source.as_ptr().cast::<c_void>().cast_mut()
464464
},
465465
self.raw().len,
466-
fort as std::ffi::c_char,
466+
fort as core::ffi::c_char,
467467
)
468468
})
469469
}
470470
}
471471

472-
impl<T> std::ops::Deref for PyBuffer<T> {
472+
impl<T> core::ops::Deref for PyBuffer<T> {
473473
type Target = PyUntypedBuffer;
474474

475475
fn deref(&self) -> &Self::Target {
@@ -524,12 +524,12 @@ impl PyUntypedBuffer {
524524
if mem::size_of::<T>() != self.item_size() || !T::is_compatible_format(self.format()) {
525525
Err(PyBufferError::new_err(format!(
526526
"buffer contents are not compatible with {}",
527-
std::any::type_name::<T>()
527+
core::any::type_name::<T>()
528528
)))
529529
} else if self.raw().buf.align_offset(mem::align_of::<T>()) != 0 {
530530
Err(PyBufferError::new_err(format!(
531531
"buffer contents are insufficiently aligned for {}",
532-
std::any::type_name::<T>()
532+
core::any::type_name::<T>()
533533
)))
534534
} else {
535535
Ok(())
@@ -691,13 +691,13 @@ impl PyUntypedBuffer {
691691
/// Gets whether the buffer is contiguous in C-style order (last index varies fastest when visiting items in order of memory address).
692692
#[inline]
693693
pub fn is_c_contiguous(&self) -> bool {
694-
unsafe { ffi::PyBuffer_IsContiguous(self.raw(), b'C' as std::ffi::c_char) != 0 }
694+
unsafe { ffi::PyBuffer_IsContiguous(self.raw(), b'C' as core::ffi::c_char) != 0 }
695695
}
696696

697697
/// Gets whether the buffer is contiguous in Fortran-style order (first index varies fastest when visiting items in order of memory address).
698698
#[inline]
699699
pub fn is_fortran_contiguous(&self) -> bool {
700-
unsafe { ffi::PyBuffer_IsContiguous(self.raw(), b'F' as std::ffi::c_char) != 0 }
700+
unsafe { ffi::PyBuffer_IsContiguous(self.raw(), b'F' as core::ffi::c_char) != 0 }
701701
}
702702

703703
fn raw(&self) -> &ffi::Py_buffer {
@@ -735,7 +735,7 @@ impl Drop for PyUntypedBuffer {
735735
}
736736
}
737737

738-
/// Like [std::cell::Cell], but only provides read-only access to the data.
738+
/// Like [core::cell::Cell], but only provides read-only access to the data.
739739
///
740740
/// `&ReadOnlyCell<T>` is basically a safe version of `*const T`:
741741
/// The data cannot be modified through the reference, but other references may
@@ -817,7 +817,7 @@ mod tests {
817817
#[test]
818818
fn test_element_type_from_format() {
819819
use super::ElementType::*;
820-
use std::mem::size_of;
820+
use core::mem::size_of;
821821

822822
for (cstr, expected) in [
823823
// @ prefix goes to native_element_type_from_type_char
@@ -943,8 +943,8 @@ mod tests {
943943
fn test_compatible_size() {
944944
// for the cast in PyBuffer::shape()
945945
assert_eq!(
946-
std::mem::size_of::<ffi::Py_ssize_t>(),
947-
std::mem::size_of::<usize>()
946+
core::mem::size_of::<ffi::Py_ssize_t>(),
947+
core::mem::size_of::<usize>()
948948
);
949949
}
950950

src/byteswriter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use crate::{
1616
py_result_ext::PyResultExt,
1717
};
1818
use crate::{types::PyBytes, Bound, IntoPyObject, PyErr, PyResult, Python};
19-
use std::io::IoSlice;
2019
#[cfg(not(Py_LIMITED_API))]
21-
use std::{
20+
use core::{
2221
mem::ManuallyDrop,
2322
ptr::{self, NonNull},
2423
};
24+
use std::io::IoSlice;
2525

2626
pub struct PyBytesWriter<'py> {
2727
python: Python<'py>,
@@ -194,7 +194,7 @@ impl std::io::Write for PyBytesWriter<'_> {
194194
}
195195

196196
#[cfg(Py_LIMITED_API)]
197-
impl std::io::Write for PyBytesWriter<'_> {
197+
impl core::io::Write for PyBytesWriter<'_> {
198198
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
199199
self.buffer.write(buf)
200200
}
@@ -211,7 +211,7 @@ impl std::io::Write for PyBytesWriter<'_> {
211211
self.buffer.write_all(buf)
212212
}
213213

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

src/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'py> PyCallArgs<'py> for Borrowed<'_, 'py, PyTuple> {
207207
_: private::Token,
208208
) -> PyResult<Bound<'py, PyAny>> {
209209
unsafe {
210-
ffi::PyObject_Call(function.as_ptr(), self.as_ptr(), std::ptr::null_mut())
210+
ffi::PyObject_Call(function.as_ptr(), self.as_ptr(), core::ptr::null_mut())
211211
.assume_owned_or_err(function.py())
212212
}
213213
}

src/conversion.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
Borrowed, Bound, BoundObject, Py, PyAny, PyClass, PyClassGuard, PyErr, PyRef, PyRefMut,
1212
PyTypeCheck, Python,
1313
};
14-
use std::convert::Infallible;
15-
use std::marker::PhantomData;
14+
use core::convert::Infallible;
15+
use core::marker::PhantomData;
1616

1717
/// Defines a conversion from a Rust type to a Python object, which may fail.
1818
///
@@ -375,9 +375,9 @@ impl<'py, T> IntoPyObjectExt<'py> for T where T: IntoPyObject<'py> {}
375375
/// The output type may also depend on the Python lifetime `'py`. This allows the output type to
376376
/// keep interacting with the Python interpreter. See also [`Bound<'py, T>`].
377377
///
378-
/// [`Cow<'a, str>`]: std::borrow::Cow
379-
/// [`Cow::Borrowed`]: std::borrow::Cow::Borrowed
380-
/// [`Cow::Owned`]: std::borrow::Cow::Owned
378+
/// [`Cow<'a, str>`]: alloc::borrow::Cow
379+
/// [`Cow::Borrowed`]: alloc::borrow::Cow::Borrowed
380+
/// [`Cow::Owned`]: alloc::borrow::Cow::Owned
381381
/// [guide]: https://pyo3.rs/latest/conversions/traits.html#deriving-frompyobject
382382
pub trait FromPyObject<'a, 'py>: Sized {
383383
/// The type returned in the event of a conversion error.
@@ -506,7 +506,7 @@ pub(crate) use from_py_object_sequence::FromPyObjectSequence;
506506
/// ```
507507
///
508508
/// [`PyList`]: crate::types::PyList
509-
/// [`Arc<T>`]: std::sync::Arc
509+
/// [`Arc<T>`]: alloc::sync::Arc
510510
pub trait FromPyObjectOwned<'py>: for<'a> FromPyObject<'a, 'py> {}
511511
impl<'py, T> FromPyObjectOwned<'py> for T where T: for<'a> FromPyObject<'a, 'py> {}
512512

src/conversions/anyhow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
//! # Example: Using `anyhow` in general
5757
//!
5858
//! Note that you don't need this feature to convert a [`PyErr`] into an [`anyhow::Error`], because
59-
//! it can already convert anything that implements [`Error`](std::error::Error):
59+
//! it can already convert anything that implements [`Error`](core::error::Error):
6060
//!
6161
//! ```rust
6262
//! use pyo3::prelude::*;

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
@@ -118,8 +118,8 @@ where
118118
// is not experimental, rather than the Rust type names.
119119
let err_msg = format!(
120120
"failed to convert the value to 'Union[{}, {}]'",
121-
std::any::type_name::<L>(),
122-
std::any::type_name::<R>()
121+
core::any::type_name::<L>(),
122+
core::any::type_name::<R>()
123123
);
124124
Err(PyTypeError::new_err(err_msg))
125125
}
@@ -128,7 +128,7 @@ where
128128

129129
#[cfg(test)]
130130
mod tests {
131-
use std::borrow::Cow;
131+
use alloc::borrow::Cow;
132132

133133
use crate::exceptions::PyTypeError;
134134
use crate::{IntoPyObject, Python};

src/conversions/eyre.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//! # Example: Using `eyre` in general
5959
//!
6060
//! Note that you don't need this feature to convert a [`PyErr`] into an [`eyre::Report`], because
61-
//! it can already convert anything that implements [`Error`](std::error::Error):
61+
//! it can already convert anything that implements [`Error`](core::error::Error):
6262
//!
6363
//! ```rust
6464
//! use pyo3::prelude::*;

0 commit comments

Comments
 (0)