Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 22 additions & 22 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
use crate::inspect::{type_hint_identifier, PyStaticExpr};
use crate::{err, exceptions::PyBufferError, ffi, FromPyObject, PyAny, PyResult, Python};
use crate::{Borrowed, Bound, PyErr};
use std::ffi::{
use core::ffi::{
c_char, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, c_ulong, c_ulonglong,
c_ushort, c_void,
};
use std::marker::{PhantomData, PhantomPinned};
use std::pin::Pin;
use std::ptr::NonNull;
use std::{cell, mem, ptr, slice};
use std::{ffi::CStr, fmt::Debug};
use core::marker::{PhantomData, PhantomPinned};
use core::pin::Pin;
use core::ptr::NonNull;
use core::{cell, mem, ptr, slice};
use core::{ffi::CStr, fmt::Debug};

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

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

impl Debug for PyUntypedBuffer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_buffer("PyUntypedBuffer", self, f)
}
}

fn debug_buffer(
name: &str,
b: &PyUntypedBuffer,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
f: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result {
let raw = b.raw();
f.debug_struct(name)
.field("buf", &raw.buf)
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<T: Element> PyBuffer<T> {
#[cfg(not(Py_3_11))]
ptr::from_ref(self.raw()).cast_mut(),
self.raw().len,
fort as std::ffi::c_char,
fort as core::ffi::c_char,
)
})
}
Expand Down Expand Up @@ -401,7 +401,7 @@ impl<T: Element> PyBuffer<T> {
#[cfg(not(Py_3_11))]
ptr::from_ref(self.raw()).cast_mut(),
self.raw().len,
fort as std::ffi::c_char,
fort as core::ffi::c_char,
)
})?;
// set vector length to mark the now-initialized space as usable
Expand Down Expand Up @@ -463,13 +463,13 @@ impl<T: Element> PyBuffer<T> {
source.as_ptr().cast::<c_void>().cast_mut()
},
self.raw().len,
fort as std::ffi::c_char,
fort as core::ffi::c_char,
)
})
}
}

impl<T> std::ops::Deref for PyBuffer<T> {
impl<T> core::ops::Deref for PyBuffer<T> {
type Target = PyUntypedBuffer;

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

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

fn raw(&self) -> &ffi::Py_buffer {
Expand Down Expand Up @@ -735,7 +735,7 @@ impl Drop for PyUntypedBuffer {
}
}

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

for (cstr, expected) in [
// @ prefix goes to native_element_type_from_type_char
Expand Down Expand Up @@ -943,8 +943,8 @@ mod tests {
fn test_compatible_size() {
// for the cast in PyBuffer::shape()
assert_eq!(
std::mem::size_of::<ffi::Py_ssize_t>(),
std::mem::size_of::<usize>()
core::mem::size_of::<ffi::Py_ssize_t>(),
core::mem::size_of::<usize>()
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/byteswriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::{
py_result_ext::PyResultExt,
};
use crate::{types::PyBytes, Bound, IntoPyObject, PyErr, PyResult, Python};
use std::io::IoSlice;
#[cfg(not(Py_LIMITED_API))]
use std::{
use core::{
mem::ManuallyDrop,
ptr::{self, NonNull},
};
use std::io::IoSlice;

pub struct PyBytesWriter<'py> {
python: Python<'py>,
Expand Down Expand Up @@ -211,7 +211,7 @@ impl std::io::Write for PyBytesWriter<'_> {
self.buffer.write_all(buf)
}

fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> {
fn write_fmt(&mut self, args: core::fmt::Arguments<'_>) -> std::io::Result<()> {
self.buffer.write_fmt(args)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'py> PyCallArgs<'py> for Borrowed<'_, 'py, PyTuple> {
_: private::Token,
) -> PyResult<Bound<'py, PyAny>> {
unsafe {
ffi::PyObject_Call(function.as_ptr(), self.as_ptr(), std::ptr::null_mut())
ffi::PyObject_Call(function.as_ptr(), self.as_ptr(), core::ptr::null_mut())
.assume_owned_or_err(function.py())
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
Borrowed, Bound, BoundObject, Py, PyAny, PyClass, PyClassGuard, PyErr, PyRef, PyRefMut,
PyTypeCheck, Python,
};
use std::convert::Infallible;
use std::marker::PhantomData;
use core::convert::Infallible;
use core::marker::PhantomData;

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

Expand Down
2 changes: 1 addition & 1 deletion src/conversions/anyhow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
//! # Example: Using `anyhow` in general
//!
//! Note that you don't need this feature to convert a [`PyErr`] into an [`anyhow::Error`], because
//! it can already convert anything that implements [`Error`](std::error::Error):
//! it can already convert anything that implements [`Error`](core::error::Error):
//!
//! ```rust
//! use pyo3::prelude::*;
Expand Down
4 changes: 2 additions & 2 deletions src/conversions/bigdecimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
//! assert d + 1 == value
//! ```

use std::str::FromStr;
use core::str::FromStr;

#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
Expand Down Expand Up @@ -121,7 +121,7 @@ mod test_bigdecimal {
use super::*;
use crate::types::dict::PyDictMethods;
use crate::types::PyDict;
use std::ffi::CString;
use alloc::ffi::CString;

use bigdecimal::{One, Zero};
#[cfg(not(target_arch = "wasm32"))]
Expand Down
9 changes: 5 additions & 4 deletions src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ fn warn_truncated_leap_second(obj: &Bound<'_, PyAny>) {

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

#[cfg(not(Py_LIMITED_API))]
fn py_time_to_naive_time(
py_time: impl std::ops::Deref<Target = impl PyTimeAccess>,
py_time: impl core::ops::Deref<Target = impl PyTimeAccess>,
) -> PyResult<NaiveTime> {
NaiveTime::from_hms_micro_opt(
py_time.get_hour().into(),
Expand Down Expand Up @@ -715,7 +715,8 @@ fn py_datetime_to_datetime_with_timezone<Tz: TimeZone>(
mod tests {
use super::*;
use crate::{test_utils::assert_warnings, types::PyTuple, BoundObject};
use std::{cmp::Ordering, panic};
use core::cmp::Ordering;
use std::panic;

#[test]
// Only Python>=3.9 has the zoneinfo package
Expand Down Expand Up @@ -1312,8 +1313,8 @@ mod tests {
use super::*;
use crate::test_utils::CatchWarnings;
use crate::types::IntoPyDict;
use alloc::ffi::CString;
use proptest::prelude::*;
use std::ffi::CString;

proptest! {

Expand Down
4 changes: 2 additions & 2 deletions src/conversions/chrono_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use crate::types::{any::PyAnyMethods, PyTzInfo};
#[cfg(all(feature = "experimental-inspect", not(Py_3_9)))]
use crate::PyTypeInfo;
use crate::{intern, Borrowed, Bound, FromPyObject, PyAny, PyErr, Python};
use alloc::borrow::Cow;
use chrono_tz::Tz;
use std::borrow::Cow;
use std::str::FromStr;
use core::str::FromStr;

impl<'py> IntoPyObject<'py> for Tz {
type Target = PyTzInfo;
Expand Down
6 changes: 3 additions & 3 deletions src/conversions/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ where
// is not experimental, rather than the Rust type names.
let err_msg = format!(
"failed to convert the value to 'Union[{}, {}]'",
std::any::type_name::<L>(),
std::any::type_name::<R>()
core::any::type_name::<L>(),
core::any::type_name::<R>()
);
Err(PyTypeError::new_err(err_msg))
}
Expand All @@ -128,7 +128,7 @@ where

#[cfg(test)]
mod tests {
use std::borrow::Cow;
use alloc::borrow::Cow;

use crate::exceptions::PyTypeError;
use crate::{IntoPyObject, Python};
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/eyre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//! # Example: Using `eyre` in general
//!
//! Note that you don't need this feature to convert a [`PyErr`] into an [`eyre::Report`], because
//! it can already convert anything that implements [`Error`](std::error::Error):
//! it can already convert anything that implements [`Error`](core::error::Error):
//!
//! ```rust
//! use pyo3::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/hashbrown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
};
#[cfg(feature = "experimental-inspect")]
use crate::{type_hint_subscript, type_hint_union, PyTypeInfo};
use std::hash;
use core::hash;

impl<'py, K, V, H> IntoPyObject<'py> for hashbrown::HashMap<K, V, H>
where
Expand Down
2 changes: 1 addition & 1 deletion src/conversions/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use crate::types::*;
#[cfg(feature = "experimental-inspect")]
use crate::{type_hint_subscript, PyTypeInfo};
use crate::{Borrowed, Bound, FromPyObject, PyErr, Python};
use std::hash;
use core::hash;

impl<'py, K, V, H> IntoPyObject<'py> for indexmap::IndexMap<K, V, H>
where
Expand Down
Loading
Loading