Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//! `PyBuffer` implementation
#[cfg(feature = "experimental-inspect")]
use crate::inspect::{type_hint_identifier, PyStaticExpr};
use crate::platform::prelude::*;
use crate::{err, exceptions::PyBufferError, ffi, FromPyObject, PyAny, PyResult, Python};
use crate::{Borrowed, Bound, PyErr};
use core::ffi::{
Expand Down
2 changes: 2 additions & 0 deletions src/byteswriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::PyTypeInfo;
#[cfg(not(Py_LIMITED_API))]
Expand Down
2 changes: 2 additions & 0 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::err::PyResult;
use crate::impl_::pyclass::ExtractPyClassWithClone;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::{type_hint_identifier, type_hint_subscript, PyStaticExpr};
use crate::platform::prelude::*;
use crate::pyclass::boolean_struct::False;
use crate::pyclass::{PyClassGuardError, PyClassGuardMutError};
use crate::types::PyList;
Expand Down Expand Up @@ -441,6 +442,7 @@ pub trait FromPyObject<'a, 'py>: Sized {
}

mod from_py_object_sequence {
use crate::platform::prelude::*;
use crate::PyResult;

/// Private trait for implementing specialized sequence extraction for `Vec<u8>` and `[u8; N]`
Expand Down
1 change: 1 addition & 0 deletions src/conversions/anyhow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl From<anyhow::Error> for PyErr {
#[cfg(test)]
mod test_anyhow {
use crate::exceptions::{PyRuntimeError, PyValueError};
use crate::platform::prelude::*;
use crate::prelude::*;
use crate::types::IntoPyDict;

Expand Down
1 change: 1 addition & 0 deletions src/conversions/bigdecimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use core::str::FromStr;

#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::type_hint_identifier;
use crate::types::PyTuple;
Expand Down
2 changes: 2 additions & 0 deletions src/conversions/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ use crate::conversion::IntoPyObject;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::instance::Bound;
#[allow(unused_imports, reason = "used to build docs")]
use crate::platform::prelude::*;
Comment thread
Person-93 marked this conversation as resolved.
use crate::pybacked::PyBackedBytes;
use crate::types::PyBytes;
#[cfg(feature = "experimental-inspect")]
Expand Down
10 changes: 5 additions & 5 deletions src/conversions/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ fn py_datetime_to_datetime_with_timezone<Tz: TimeZone>(
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::prelude::*;
use crate::{test_utils::assert_warnings, types::PyTuple, BoundObject};
use core::cmp::Ordering;
use std::panic;

#[test]
// Only Python>=3.9 has the zoneinfo package
Expand Down Expand Up @@ -898,9 +898,9 @@ mod tests {
Python::attach(|py| {
let low_days: i32 = -1000000000;
// This is possible
assert!(panic::catch_unwind(|| Duration::days(low_days as i64)).is_ok());
assert!(std::panic::catch_unwind(|| Duration::days(low_days as i64)).is_ok());
// This panics on PyDelta::new
assert!(panic::catch_unwind(|| {
assert!(std::panic::catch_unwind(|| {
let py_delta = new_py_datetime_ob(py, "timedelta", (low_days, 0, 0));
if let Ok(_duration) = py_delta.extract::<Duration>() {
// So we should never get here
Expand All @@ -910,9 +910,9 @@ mod tests {

let high_days: i32 = 1000000000;
// This is possible
assert!(panic::catch_unwind(|| Duration::days(high_days as i64)).is_ok());
assert!(std::panic::catch_unwind(|| Duration::days(high_days as i64)).is_ok());
// This panics on PyDelta::new
assert!(panic::catch_unwind(|| {
assert!(std::panic::catch_unwind(|| {
let py_delta = new_py_datetime_ob(py, "timedelta", (high_days, 0, 0));
if let Ok(_duration) = py_delta.extract::<Duration>() {
// So we should never get here
Expand Down
1 change: 1 addition & 0 deletions src/conversions/chrono_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::conversion::IntoPyObject;
use crate::exceptions::PyValueError;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::type_hint_identifier;
use crate::types::{any::PyAnyMethods, PyTzInfo};
Expand Down
1 change: 1 addition & 0 deletions src/conversions/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ mod tests {
use alloc::borrow::Cow;

use crate::exceptions::PyTypeError;
use crate::platform::prelude::*;
use crate::{IntoPyObject, Python};

use crate::types::PyAnyMethods;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/eyre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl From<eyre::Report> for PyErr {
#[cfg(test)]
mod tests {
use crate::exceptions::{PyRuntimeError, PyValueError};
use crate::platform::prelude::*;
use crate::prelude::*;
use crate::types::IntoPyDict;

Expand Down
1 change: 1 addition & 0 deletions src/conversions/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use crate::exceptions::{PyTypeError, PyValueError};
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
use crate::types::{PyAnyMethods, PyNone};
use crate::types::{PyDate, PyDateTime, PyDelta, PyTime, PyTzInfo, PyTzInfoAccess};
#[cfg(not(Py_LIMITED_API))]
Expand Down
8 changes: 5 additions & 3 deletions src/conversions/num_bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
//! assert n + 1 == value
//! ```

#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
#[cfg(Py_LIMITED_API)]
use crate::types::{bytes::PyBytesMethods, PyBytes};
use crate::{
conversion::IntoPyObject, std::num::nb_index, types::PyInt, Borrowed, Bound, FromPyObject,
PyAny, PyErr, PyResult, Python,
conversion::IntoPyObject, conversions::std::num::nb_index, types::PyInt, Borrowed, Bound,
FromPyObject, PyAny, PyErr, PyResult, Python,
};

use num_bigint::{BigInt, BigUint};
Expand Down Expand Up @@ -437,7 +439,7 @@ class C:
macro_rules! test {
($T:ty, $value:expr, $py:expr) => {
let value = $value;
println!("{}: {}", stringify!($T), value);
std::println!("{}: {}", stringify!($T), value);
let python_value = value.clone().into_pyobject(py).unwrap();
let roundtrip_value = python_value.extract::<$T>().unwrap();
assert_eq!(value, roundtrip_value);
Expand Down
1 change: 1 addition & 0 deletions src/conversions/ordered_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use crate::conversion::IntoPyObject;
use crate::exceptions::PyValueError;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
use crate::types::PyFloat;
use crate::{Borrowed, Bound, FromPyObject, PyAny, Python};
use core::convert::Infallible;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/rust_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::conversion::IntoPyObject;
use crate::exceptions::PyValueError;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
use crate::sync::PyOnceLock;
#[cfg(feature = "experimental-inspect")]
use crate::type_hint_identifier;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! serde = "1.0"
//! ```

use crate::platform::prelude::*;
use crate::{Py, PyAny, PyClass, Python};
use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer};

Expand Down
1 change: 1 addition & 0 deletions src/conversions/smallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::prelude::*;
use crate::types::{PyBytes, PyBytesMethods, PyDict, PyList};

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/conversions/std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub(crate) fn invalid_sequence_length(expected: usize, actual: usize) -> PyErr {

#[cfg(test)]
mod tests {
use crate::platform::prelude::*;
#[cfg(panic = "unwind")]
use core::sync::atomic::{AtomicUsize, Ordering};
#[cfg(panic = "unwind")]
Expand Down
2 changes: 2 additions & 0 deletions src/conversions/std/cstring.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::exceptions::PyUnicodeDecodeError;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::type_object::PyTypeInfo;
use crate::types::PyString;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/std/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::conversion::{FromPyObjectSequence, IntoPyObject};
use crate::ffi_ptr_ext::FfiPtrExt;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
use crate::py_result_ext::PyResultExt;
#[cfg(feature = "experimental-inspect")]
use crate::type_object::PyTypeInfo;
Expand Down
4 changes: 4 additions & 0 deletions src/conversions/std/osstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::ffi_ptr_ext::FfiPtrExt;
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::instance::Bound;
#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::type_object::PyTypeInfo;
use crate::types::PyString;
Expand Down Expand Up @@ -229,6 +231,8 @@ impl<'py> IntoPyObject<'py> for &OsString {
mod tests {
#[cfg(target_os = "wasi")]
use crate::exceptions::PyFileNotFoundError;
#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
use crate::types::{PyAnyMethods, PyString, PyStringMethods};
use crate::{Bound, BoundObject, IntoPyObject, Python};
use alloc::borrow::Cow;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/std/slice.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::platform::prelude::*;
use alloc::borrow::Cow;

#[cfg(feature = "experimental-inspect")]
Expand Down
2 changes: 2 additions & 0 deletions src/conversions/std/string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "experimental-inspect")]
use crate::inspect::PyStaticExpr;
use crate::platform::prelude::*;
#[cfg(feature = "experimental-inspect")]
use crate::type_object::PyTypeInfo;
use crate::{
Expand Down Expand Up @@ -177,6 +178,7 @@ impl FromPyObject<'_, '_> for char {

#[cfg(test)]
mod tests {
use crate::platform::prelude::*;
use crate::types::any::PyAnyMethods;
use crate::{IntoPyObject, Python};
use alloc::borrow::Cow;
Expand Down
1 change: 1 addition & 0 deletions src/conversions/std/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn unix_epoch_py(py: Python<'_>) -> PyResult<Borrowed<'_, '_, PyDateTime>> {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::prelude::*;
use crate::types::PyDict;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/conversions/std/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#[cfg(feature = "experimental-inspect")]
use crate::inspect::{type_hint_subscript, PyStaticExpr};
use crate::platform::prelude::*;
use crate::{
conversion::{FromPyObject, FromPyObjectOwned, FromPyObjectSequence, IntoPyObject},
exceptions::PyTypeError,
Expand Down Expand Up @@ -95,6 +96,7 @@ where
#[cfg(test)]
mod tests {
use crate::conversion::IntoPyObject;
use crate::platform::prelude::*;
use crate::types::{PyAnyMethods, PyBytes, PyBytesMethods, PyList};
use crate::Python;

Expand Down
1 change: 1 addition & 0 deletions src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::{

use pyo3_macros::{pyclass, pymethods};

use crate::platform::prelude::*;
use crate::{
coroutine::{cancel::ThrowCallback, waker::AsyncioWaker},
exceptions::{PyAttributeError, PyRuntimeError, PyStopIteration},
Expand Down
1 change: 1 addition & 0 deletions src/err/cast_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::platform::prelude::*;
use alloc::borrow::Cow;

use crate::{
Expand Down
4 changes: 3 additions & 1 deletion src/err/err_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO https://github.com/PyO3/pyo3/issues/5487
#![allow(clippy::undocumented_unsafe_blocks)]

use crate::platform::prelude::*;
use core::cell::UnsafeCell;
use std::{
sync::{Mutex, Once},
Expand Down Expand Up @@ -408,7 +409,8 @@ fn raise_lazy(py: Python<'_>, lazy: Box<PyErrStateLazyFn>) {

#[cfg(test)]
mod tests {

#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
use crate::{
exceptions::PyValueError, sync::PyOnceLock, Py, PyAny, PyErr, PyErrArguments, Python,
};
Expand Down
1 change: 1 addition & 0 deletions src/err/impls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::platform::prelude::*;
use crate::{err::PyErrArguments, exceptions, types, PyErr, Python};
use crate::{IntoPyObject, Py, PyAny};
use std::io;
Expand Down
2 changes: 2 additions & 0 deletions src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::instance::Bound;
#[cfg(Py_3_11)]
use crate::intern;
use crate::panic::PanicException;
use crate::platform::prelude::*;
use crate::py_result_ext::PyResultExt;
use crate::type_object::PyTypeInfo;
use crate::types::any::PyAnyMethods;
Expand Down Expand Up @@ -798,6 +799,7 @@ mod tests {
use super::PyErrState;
use crate::exceptions::{self, PyTypeError, PyValueError};
use crate::impl_::pyclass::{value_of, IsSend, IsSync};
use crate::platform::prelude::*;
use crate::test_utils::assert_warnings;
use crate::{PyErr, PyTypeInfo, Python};

Expand Down
1 change: 1 addition & 0 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ pub mod socket {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::prelude::*;
use crate::types::any::PyAnyMethods;
use crate::types::{IntoPyDict, PyDict};
use crate::{IntoPyObjectExt as _, PyErr};
Expand Down
7 changes: 4 additions & 3 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// TODO https://github.com/PyO3/pyo3/issues/5487
#![allow(clippy::undocumented_unsafe_blocks)]

#[allow(unused_imports, reason = "used to build docs")]
use crate::platform::prelude::*;
#[cfg(any(doc, all(Py_3_14, not(Py_LIMITED_API))))]
use crate::{types::PyString, Python};
#[cfg(all(Py_3_14, not(Py_LIMITED_API)))]
Expand Down Expand Up @@ -42,12 +44,11 @@ macro_rules! py_format {
($py: expr, $($arg:tt)*) => {{
if let Some(static_string) = format_args!($($arg)*).as_str() {
static INTERNED: $crate::sync::PyOnceLock<$crate::Py<$crate::types::PyString>> = $crate::sync::PyOnceLock::new();
Ok(
Ok($crate::Bound::clone(
INTERNED
.get_or_init($py, || $crate::types::PyString::intern($py, static_string).unbind())
.bind($py)
.to_owned()
)
))
} else {
$crate::types::PyString::from_fmt($py, format_args!($($arg)*))
}
Expand Down
2 changes: 2 additions & 0 deletions src/impl_/extract_argument.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO https://github.com/PyO3/pyo3/issues/5487
#![allow(clippy::undocumented_unsafe_blocks)]

use crate::platform::prelude::*;
use core::ptr::NonNull;

#[cfg(feature = "experimental-inspect")]
Expand Down Expand Up @@ -1021,6 +1022,7 @@ fn push_parameter_list(msg: &mut String, parameter_names: &[&str]) {

#[cfg(test)]
mod tests {
use crate::platform::prelude::*;
use crate::types::{IntoPyDict, PyTuple};
use crate::Python;

Expand Down
1 change: 1 addition & 0 deletions src/impl_/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! [1]: https://en.wikipedia.org/wiki/Free_list

use crate::ffi;
use crate::platform::prelude::*;
use core::ptr::NonNull;

/// A free allocation list for PyObject ffi pointers.
Expand Down
1 change: 1 addition & 0 deletions src/impl_/frompyobject.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::platform::prelude::*;
use crate::types::any::PyAnyMethods;
use crate::Bound;
use crate::{exceptions::PyTypeError, FromPyObject, PyAny, PyErr, PyResult, Python};
Expand Down
2 changes: 2 additions & 0 deletions src/impl_/pyclass.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// TODO https://github.com/PyO3/pyo3/issues/5487
#![allow(clippy::undocumented_unsafe_blocks)]

#[allow(unused_imports, reason = "conditionally used")]
use crate::platform::prelude::*;
use crate::{
exceptions::{PyAttributeError, PyNotImplementedError, PyRuntimeError},
ffi,
Expand Down
1 change: 1 addition & 0 deletions src/impl_/pyclass/lazy_type_object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO https://github.com/PyO3/pyo3/issues/5487
#![allow(clippy::undocumented_unsafe_blocks)]

use crate::platform::prelude::*;
use core::{ffi::CStr, marker::PhantomData};
use std::thread::{self, ThreadId};

Expand Down
Loading