From ca7a098e43b2e089f12e5cf516471a92eb423d48 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 14 Mar 2025 21:28:07 +0000 Subject: [PATCH 1/3] remove all functionality deprecated in PyO3 0.23 (except `IntoPy` and `ToPyObject`) --- guide/src/migration.md | 2 +- guide/src/python-from-rust.md | 4 +- newsfragments/4982.removed.md | 1 + pyo3-benches/benches/bench_list.rs | 4 +- src/buffer.rs | 7 -- src/err/mod.rs | 124 +------------------------ src/exceptions.rs | 24 ----- src/instance.rs | 33 +------ src/lib.rs | 20 ---- src/macros.rs | 20 +--- src/marker.rs | 73 +++------------ src/marshal.rs | 19 ---- src/prelude.rs | 3 - src/type_object.rs | 21 ----- src/types/any.rs | 37 -------- src/types/boolobject.rs | 7 -- src/types/bytearray.rs | 28 ------ src/types/bytes.rs | 31 ------- src/types/capsule.rs | 26 ------ src/types/complex.rs | 11 --- src/types/datetime.rs | 143 +---------------------------- src/types/dict.rs | 22 ----- src/types/ellipsis.rs | 7 -- src/types/float.rs | 7 -- src/types/frozenset.rs | 25 ----- src/types/function.rs | 42 --------- src/types/iterator.rs | 9 +- src/types/list.rs | 23 ----- src/types/memoryview.rs | 7 -- src/types/mod.rs | 10 +- src/types/module.rs | 41 +-------- src/types/none.rs | 7 -- src/types/notimplemented.rs | 7 -- src/types/num.rs | 4 - src/types/pysuper.rs | 10 -- src/types/set.rs | 18 ---- src/types/slice.rs | 14 --- src/types/string.rs | 33 +------ src/types/tuple.rs | 23 ----- src/types/typeobject.rs | 7 -- src/types/weakref/anyref.rs | 142 +--------------------------- src/types/weakref/proxy.rs | 73 --------------- src/types/weakref/reference.rs | 62 ------------- 43 files changed, 40 insertions(+), 1191 deletions(-) create mode 100644 newsfragments/4982.removed.md diff --git a/guide/src/migration.md b/guide/src/migration.md index 35126dfcaef..816399f48d0 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -179,7 +179,7 @@ With the removal of the old API, many "Bound" API functions which had been intro Before: -```rust +```rust,ignore # #![allow(deprecated)] # use pyo3::prelude::*; # use pyo3::types::PyTuple; diff --git a/guide/src/python-from-rust.md b/guide/src/python-from-rust.md index ebb7fa1f4da..7ab39161e70 100644 --- a/guide/src/python-from-rust.md +++ b/guide/src/python-from-rust.md @@ -17,7 +17,7 @@ are met. Its lifetime `'py` is a central part of PyO3's API. The `Python<'py>` token serves three purposes: -* It provides global APIs for the Python interpreter, such as [`py.eval_bound()`][eval] and [`py.import_bound()`][import]. +* It provides global APIs for the Python interpreter, such as [`py.eval()`][eval] and [`py.import()`][import]. * It can be passed to functions that require a proof of holding the GIL, such as [`Py::clone_ref`][clone_ref]. * Its lifetime `'py` is used to bind many of PyO3's types to the Python interpreter, such as [`Bound<'py, T>`][Bound]. @@ -45,6 +45,6 @@ Because of the lack of exclusive `&mut` references, PyO3's APIs for Python objec [obtaining-py]: {{#PYO3_DOCS_URL}}/pyo3/marker/struct.Python.html#obtaining-a-python-token [`pyo3::sync`]: {{#PYO3_DOCS_URL}}/pyo3/sync/index.html [eval]: {{#PYO3_DOCS_URL}}/pyo3/marker/struct.Python.html#method.eval -[import]: {{#PYO3_DOCS_URL}}/pyo3/marker/struct.Python.html#method.import_bound +[import]: {{#PYO3_DOCS_URL}}/pyo3/marker/struct.Python.html#method.import [clone_ref]: {{#PYO3_DOCS_URL}}/pyo3/prelude/struct.Py.html#method.clone_ref [Bound]: {{#PYO3_DOCS_URL}}/pyo3/struct.Bound.html diff --git a/newsfragments/4982.removed.md b/newsfragments/4982.removed.md new file mode 100644 index 00000000000..61f9dedbc48 --- /dev/null +++ b/newsfragments/4982.removed.md @@ -0,0 +1 @@ +Remove all functionality deprecated in PyO3 0.23. diff --git a/pyo3-benches/benches/bench_list.rs b/pyo3-benches/benches/bench_list.rs index 7a19452455e..bb47d824c4e 100644 --- a/pyo3-benches/benches/bench_list.rs +++ b/pyo3-benches/benches/bench_list.rs @@ -42,7 +42,7 @@ fn list_get_item(b: &mut Bencher<'_>) { fn list_nth(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50; - let list = PyList::new_bound(py, 0..LEN); + let list = PyList::new(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -55,7 +55,7 @@ fn list_nth(b: &mut Bencher<'_>) { fn list_nth_back(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50; - let list = PyList::new_bound(py, 0..LEN); + let list = PyList::new(py, 0..LEN); let mut sum = 0; b.iter(|| { for i in 0..LEN { diff --git a/src/buffer.rs b/src/buffer.rs index 2d94681a5c7..c5e5de568eb 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -224,13 +224,6 @@ impl PyBuffer { } } - /// Deprecated name for [`PyBuffer::get`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyBuffer::get`")] - #[inline] - pub fn get_bound(obj: &Bound<'_, PyAny>) -> PyResult> { - Self::get(obj) - } - /// Gets the pointer to the start of the buffer memory. /// /// Warning: the buffer memory might be mutated by other Python functions, diff --git a/src/err/mod.rs b/src/err/mod.rs index bd026bab14d..21e89efcf8e 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -14,7 +14,7 @@ use crate::{Borrowed, BoundObject, Py, PyAny, PyObject, Python}; #[allow(deprecated)] use crate::{IntoPy, ToPyObject}; use std::borrow::Cow; -use std::ffi::{CStr, CString}; +use std::ffi::CStr; mod err_state; mod impls; @@ -29,8 +29,8 @@ use std::convert::Infallible; /// compatibility with `?` and other Rust errors) this type supports creating exceptions instances /// in a lazy fashion, where the full Python object for the exception is created only when needed. /// -/// Accessing the contained exception in any way, such as with [`value_bound`](PyErr::value_bound), -/// [`get_type_bound`](PyErr::get_type_bound), or [`is_instance_bound`](PyErr::is_instance_bound) +/// Accessing the contained exception in any way, such as with [`value`](PyErr::value), +/// [`get_type`](PyErr::get_type), or [`is_instance`](PyErr::is_instance) /// will create the full exception object if it was not already created. pub struct PyErr { state: PyErrState, @@ -126,7 +126,7 @@ impl PyErr { /// /// This exception instance will be initialized lazily. This avoids the need for the Python GIL /// to be held, but requires `args` to be `Send` and `Sync`. If `args` is not `Send` or `Sync`, - /// consider using [`PyErr::from_value_bound`] instead. + /// consider using [`PyErr::from_value`] instead. /// /// If `T` does not inherit from `BaseException`, then a `TypeError` will be returned. /// @@ -198,16 +198,6 @@ impl PyErr { PyErr::from_state(PyErrState::lazy_arguments(ty.unbind().into_any(), args)) } - /// Deprecated name for [`PyErr::from_type`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::from_type`")] - #[inline] - pub fn from_type_bound(ty: Bound<'_, PyType>, args: A) -> PyErr - where - A: PyErrArguments + Send + Sync + 'static, - { - Self::from_type(ty, args) - } - /// Creates a new PyErr. /// /// If `obj` is a Python exception object, the PyErr will contain that object. @@ -256,13 +246,6 @@ impl PyErr { PyErr::from_state(state) } - /// Deprecated name for [`PyErr::from_value`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::from_value`")] - #[inline] - pub fn from_value_bound(obj: Bound<'_, PyAny>) -> PyErr { - Self::from_value(obj) - } - /// Returns the type of this exception. /// /// # Examples @@ -278,13 +261,6 @@ impl PyErr { self.normalized(py).ptype(py) } - /// Deprecated name for [`PyErr::get_type`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::get_type`")] - #[inline] - pub fn get_type_bound<'py>(&self, py: Python<'py>) -> Bound<'py, PyType> { - self.get_type(py) - } - /// Returns the value of this exception. /// /// # Examples @@ -302,13 +278,6 @@ impl PyErr { self.normalized(py).pvalue.bind(py) } - /// Deprecated name for [`PyErr::value`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::value`")] - #[inline] - pub fn value_bound<'py>(&self, py: Python<'py>) -> &Bound<'py, PyBaseException> { - self.value(py) - } - /// Consumes self to take ownership of the exception value contained in this error. pub fn into_value(self, py: Python<'_>) -> Py { // NB technically this causes one reference count increase and decrease in quick succession @@ -339,13 +308,6 @@ impl PyErr { self.normalized(py).ptraceback(py) } - /// Deprecated name for [`PyErr::traceback`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::traceback`")] - #[inline] - pub fn traceback_bound<'py>(&self, py: Python<'py>) -> Option> { - self.traceback(py) - } - /// Gets whether an error is present in the Python interpreter's global state. #[inline] pub fn occurred(_: Python<'_>) -> bool { @@ -449,29 +411,6 @@ impl PyErr { unsafe { Py::from_owned_ptr_or_err(py, ptr) } } - /// Deprecated name for [`PyErr::new_type`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::new_type`")] - #[inline] - pub fn new_type_bound<'py>( - py: Python<'py>, - name: &str, - doc: Option<&str>, - base: Option<&Bound<'py, PyType>>, - dict: Option, - ) -> PyResult> { - let null_terminated_name = - CString::new(name).expect("Failed to initialize nul terminated exception name"); - let null_terminated_doc = - doc.map(|d| CString::new(d).expect("Failed to initialize nul terminated docstring")); - Self::new_type( - py, - &null_terminated_name, - null_terminated_doc.as_deref(), - base, - dict, - ) - } - /// Prints a standard traceback to `sys.stderr`. pub fn display(&self, py: Python<'_>) { #[cfg(Py_3_12)] @@ -529,13 +468,6 @@ impl PyErr { (unsafe { ffi::PyErr_GivenExceptionMatches(type_bound.as_ptr(), ty.as_ptr()) }) != 0 } - /// Deprecated name for [`PyErr::is_instance`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::is_instance`")] - #[inline] - pub fn is_instance_bound(&self, py: Python<'_>, ty: &Bound<'_, PyAny>) -> bool { - self.is_instance(py, ty) - } - /// Returns true if the current exception is instance of `T`. #[inline] pub fn is_instance_of(&self, py: Python<'_>) -> bool @@ -586,13 +518,6 @@ impl PyErr { unsafe { ffi::PyErr_WriteUnraisable(obj.map_or(std::ptr::null_mut(), Bound::as_ptr)) } } - /// Deprecated name for [`PyErr::write_unraisable`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::write_unraisable`")] - #[inline] - pub fn write_unraisable_bound(self, py: Python<'_>, obj: Option<&Bound<'_, PyAny>>) { - self.write_unraisable(py, obj) - } - /// Issues a warning message. /// /// May return an `Err(PyErr)` if warnings-as-errors is enabled. @@ -601,7 +526,7 @@ impl PyErr { /// /// The `category` should be one of the `Warning` classes available in /// [`pyo3::exceptions`](crate::exceptions), or a subclass. The Python - /// object can be retrieved using [`Python::get_type_bound()`]. + /// object can be retrieved using [`Python::get_type()`]. /// /// Example: /// ```rust @@ -630,19 +555,6 @@ impl PyErr { }) } - /// Deprecated name for [`PyErr::warn`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::warn`")] - #[inline] - pub fn warn_bound<'py>( - py: Python<'py>, - category: &Bound<'py, PyAny>, - message: &str, - stacklevel: i32, - ) -> PyResult<()> { - let message = CString::new(message)?; - Self::warn(py, category, &message, stacklevel) - } - /// Issues a warning message, with more control over the warning attributes. /// /// May return a `PyErr` if warnings-as-errors is enabled. @@ -680,32 +592,6 @@ impl PyErr { }) } - /// Deprecated name for [`PyErr::warn_explicit`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyErr::warn`")] - #[inline] - pub fn warn_explicit_bound<'py>( - py: Python<'py>, - category: &Bound<'py, PyAny>, - message: &str, - filename: &str, - lineno: i32, - module: Option<&str>, - registry: Option<&Bound<'py, PyAny>>, - ) -> PyResult<()> { - let message = CString::new(message)?; - let filename = CString::new(filename)?; - let module = module.map(CString::new).transpose()?; - Self::warn_explicit( - py, - category, - &message, - &filename, - lineno, - module.as_deref(), - registry, - ) - } - /// Clone the PyErr. This requires the GIL, which is why PyErr does not implement Clone. /// /// # Examples diff --git a/src/exceptions.rs b/src/exceptions.rs index 66044a6658f..dbbc8c714f1 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -653,19 +653,6 @@ impl PyUnicodeDecodeError { .downcast_into() } - /// Deprecated name for [`PyUnicodeDecodeError::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyUnicodeDecodeError::new`")] - #[inline] - pub fn new_bound<'py>( - py: Python<'py>, - encoding: &CStr, - input: &[u8], - range: ops::Range, - reason: &CStr, - ) -> PyResult> { - Self::new(py, encoding, input, range, reason) - } - /// Creates a Python `UnicodeDecodeError` from a Rust UTF-8 decoding error. /// /// # Examples @@ -701,17 +688,6 @@ impl PyUnicodeDecodeError { ffi::c_str!("invalid utf-8"), ) } - - /// Deprecated name for [`PyUnicodeDecodeError::new_utf8`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyUnicodeDecodeError::new_utf8`")] - #[inline] - pub fn new_utf8_bound<'py>( - py: Python<'py>, - input: &[u8], - err: std::str::Utf8Error, - ) -> PyResult> { - Self::new_utf8(py, input, err) - } } impl_native_exception!(PyWarning, PyExc_Warning, native_doc!("Warning")); diff --git a/src/instance.rs b/src/instance.rs index 7a32f4c9c30..a47274e7732 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -884,7 +884,7 @@ impl<'a, 'py, T> BoundObject<'py, T> for Borrowed<'a, 'py, T> { /// See the #[doc = concat!("[guide entry](https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html#bound-and-interior-mutability)")] /// for more information. -/// - You can call methods directly on `Py` with [`Py::call_bound`], [`Py::call_method_bound`] and friends. +/// - You can call methods directly on `Py` with [`Py::call`], [`Py::call_method`] and friends. /// /// These require passing in the [`Python<'py>`](crate::Python) token but are otherwise similar to the corresponding /// methods on [`PyAny`]. @@ -1514,19 +1514,6 @@ impl Py { .map(Bound::unbind) } - /// Deprecated name for [`Py::call`]. - #[deprecated(since = "0.23.0", note = "renamed to `Py::call`")] - #[allow(deprecated)] - #[inline] - pub fn call_bound( - &self, - py: Python<'_>, - args: impl IntoPy>, - kwargs: Option<&Bound<'_, PyDict>>, - ) -> PyResult { - self.call(py, args.into_py(py), kwargs) - } - /// Calls the object with only positional arguments. /// /// This is equivalent to the Python expression `self(*args)`. @@ -1576,24 +1563,6 @@ impl Py { .map(Bound::unbind) } - /// Deprecated name for [`Py::call_method`]. - #[deprecated(since = "0.23.0", note = "renamed to `Py::call_method`")] - #[allow(deprecated)] - #[inline] - pub fn call_method_bound( - &self, - py: Python<'_>, - name: N, - args: A, - kwargs: Option<&Bound<'_, PyDict>>, - ) -> PyResult - where - N: IntoPy>, - A: IntoPy>, - { - self.call_method(py, name.into_py(py), args.into_py(py), kwargs) - } - /// Calls a method on the object with only positional arguments. /// /// This is equivalent to the Python expression `self.name(*args)`. diff --git a/src/lib.rs b/src/lib.rs index 863fd010ade..8585fbacdea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -367,26 +367,6 @@ pub(crate) mod sealed; pub mod class { pub use self::gc::{PyTraverseError, PyVisit}; - pub use self::methods::*; - - #[doc(hidden)] - pub mod methods { - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type IPowModulo = crate::impl_::pymethods::IPowModulo; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PyClassAttributeDef = crate::impl_::pymethods::PyClassAttributeDef; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PyGetterDef = crate::impl_::pymethods::PyGetterDef; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PyMethodDef = crate::impl_::pymethods::PyMethodDef; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PyMethodDefType = crate::impl_::pymethods::PyMethodDefType; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PyMethodType = crate::impl_::pymethods::PyMethodType; - #[deprecated(since = "0.23.0", note = "PyO3 implementation detail")] - pub type PySetterDef = crate::impl_::pymethods::PySetterDef; - } - /// Old module which contained some implementation details of the `#[pyproto]` module. /// /// Prefer using the same content from `pyo3::pyclass`, e.g. `use pyo3::pyclass::CompareOp` instead diff --git a/src/macros.rs b/src/macros.rs index 53fcbcaad3d..01d035f85ac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -2,10 +2,10 @@ /// /// # Panics /// -/// This macro internally calls [`Python::run_bound`](crate::Python::run_bound) and panics +/// This macro internally calls [`Python::run`](crate::Python::run) and panics /// if it returns `Err`, after printing the error to stdout. /// -/// If you need to handle failures, please use [`Python::run_bound`](crate::marker::Python::run_bound) instead. +/// If you need to handle failures, please use [`Python::run`](crate::marker::Python::run) instead. /// /// # Examples /// ``` @@ -149,22 +149,6 @@ macro_rules! wrap_pyfunction { }}; } -/// Wraps a Rust function annotated with [`#[pyfunction]`](macro@crate::pyfunction). -/// -/// This can be used with [`PyModule::add_function`](crate::types::PyModuleMethods::add_function) to -/// add free functions to a [`PyModule`](crate::types::PyModule) - see its documentation for more -/// information. -#[deprecated(since = "0.23.0", note = "renamed to `wrap_pyfunction!`")] -#[macro_export] -macro_rules! wrap_pyfunction_bound { - ($function:path) => { - $crate::wrap_pyfunction!($function) - }; - ($function:path, $py_or_module:expr) => { - $crate::wrap_pyfunction!($function, $py_or_module) - }; -} - /// Returns a function that takes a [`Python`](crate::Python) instance and returns a /// Python module. /// diff --git a/src/marker.rs b/src/marker.rs index 4fe91464244..f1ddf1847c8 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -128,10 +128,8 @@ use crate::types::{ PyAny, PyDict, PyEllipsis, PyModule, PyNone, PyNotImplemented, PyString, PyType, }; use crate::version::PythonVersionInfo; -#[allow(deprecated)] -use crate::IntoPy; -use crate::{ffi, Bound, Py, PyObject, PyTypeInfo}; -use std::ffi::{CStr, CString}; +use crate::{ffi, Bound, PyObject, PyTypeInfo}; +use std::ffi::CStr; use std::marker::PhantomData; use std::os::raw::c_int; @@ -217,7 +215,7 @@ mod nightly { /// # use pyo3::prelude::*; /// # use pyo3::types::PyString; /// Python::with_gil(|py| { - /// let string = PyString::new_bound(py, "foo"); + /// let string = PyString::new(py, "foo"); /// /// py.allow_threads(|| { /// println!("{:?}", string); @@ -245,7 +243,7 @@ mod nightly { /// use send_wrapper::SendWrapper; /// /// Python::with_gil(|py| { - /// let string = PyString::new_bound(py, "foo"); + /// let string = PyString::new(py, "foo"); /// /// let wrapped = SendWrapper::new(string); /// @@ -304,9 +302,9 @@ pub use nightly::Ungil; /// A marker token that represents holding the GIL. /// /// It serves three main purposes: -/// - It provides a global API for the Python interpreter, such as [`Python::eval_bound`]. +/// - It provides a global API for the Python interpreter, such as [`Python::eval`]. /// - It can be passed to functions that require a proof of holding the GIL, such as -/// [`Py::clone_ref`]. +/// [`Py::clone_ref`][crate::Py::clone_ref]. /// - Its lifetime represents the scope of holding the GIL which can be used to create Rust /// references that are bound to it, such as [`Bound<'py, PyAny>`]. /// @@ -354,7 +352,7 @@ pub use nightly::Ungil; /// # Releasing and freeing memory /// /// The [`Python<'py>`] type can be used to create references to variables owned by the Python -/// interpreter, using functions such as [`Python::eval_bound`] and [`PyModule::import`]. +/// interpreter, using functions such as [`Python::eval`] and [`PyModule::import`]. #[derive(Copy, Clone)] pub struct Python<'py>(PhantomData<(&'py GILGuard, NotSend)>); @@ -496,7 +494,7 @@ impl<'py> Python<'py> { /// use pyo3::types::PyString; /// /// fn parallel_print(py: Python<'_>) { - /// let s = PyString::new_bound(py, "This object cannot be accessed without holding the GIL >_<"); + /// let s = PyString::new(py, "This object cannot be accessed without holding the GIL >_<"); /// py.allow_threads(move || { /// println!("{:?}", s); // This causes a compile error. /// }); @@ -548,20 +546,6 @@ impl<'py> Python<'py> { self.run_code(code, ffi::Py_eval_input, globals, locals) } - /// Deprecated name for [`Python::eval`]. - #[deprecated(since = "0.23.0", note = "renamed to `Python::eval`")] - #[track_caller] - #[inline] - pub fn eval_bound( - self, - code: &str, - globals: Option<&Bound<'py, PyDict>>, - locals: Option<&Bound<'py, PyDict>>, - ) -> PyResult> { - let code = CString::new(code)?; - self.eval(&code, globals, locals) - } - /// Executes one or more Python statements in the given context. /// /// If `globals` is `None`, it defaults to Python module `__main__`. @@ -609,20 +593,6 @@ impl<'py> Python<'py> { }) } - /// Deprecated name for [`Python::run`]. - #[deprecated(since = "0.23.0", note = "renamed to `Python::run`")] - #[track_caller] - #[inline] - pub fn run_bound( - self, - code: &str, - globals: Option<&Bound<'py, PyDict>>, - locals: Option<&Bound<'py, PyDict>>, - ) -> PyResult<()> { - let code = CString::new(code)?; - self.run(&code, globals, locals) - } - /// Runs code in the given context. /// /// `start` indicates the type of input expected: one of `Py_single_input`, @@ -699,17 +669,6 @@ impl<'py> Python<'py> { T::type_object(self) } - /// Deprecated name for [`Python::get_type`]. - #[deprecated(since = "0.23.0", note = "renamed to `Python::get_type`")] - #[track_caller] - #[inline] - pub fn get_type_bound(self) -> Bound<'py, PyType> - where - T: PyTypeInfo, - { - self.get_type::() - } - /// Imports the Python module with the specified name. pub fn import(self, name: N) -> PyResult> where @@ -718,18 +677,6 @@ impl<'py> Python<'py> { PyModule::import(self, name) } - /// Deprecated name for [`Python::import`]. - #[deprecated(since = "0.23.0", note = "renamed to `Python::import`")] - #[allow(deprecated)] - #[track_caller] - #[inline] - pub fn import_bound(self, name: N) -> PyResult> - where - N: IntoPy>, - { - self.import(name.into_py(self)) - } - /// Gets the Python builtin value `None`. #[allow(non_snake_case)] // the Python keyword starts with uppercase #[inline] @@ -1025,6 +972,10 @@ mod tests { #[cfg(feature = "macros")] #[test] fn test_py_run_inserts_globals_2() { + use std::ffi::CString; + + use crate::Py; + #[crate::pyclass(crate = "crate")] #[derive(Clone)] struct CodeRunner { diff --git a/src/marshal.rs b/src/marshal.rs index d541da7d695..cecaa16f53b 100644 --- a/src/marshal.rs +++ b/src/marshal.rs @@ -40,19 +40,6 @@ pub fn dumps<'py>(object: &Bound<'py, PyAny>, version: i32) -> PyResult( - py: Python<'py>, - object: &impl crate::AsPyPointer, - version: i32, -) -> PyResult> { - dumps( - unsafe { object.as_ptr().assume_borrowed(py) }.as_any(), - version, - ) -} - /// Deserialize an object from bytes using the Python built-in marshal module. pub fn loads<'py, B>(py: Python<'py>, data: &B) -> PyResult> where @@ -65,12 +52,6 @@ where } } -/// Deprecated form of [`loads`]. -#[deprecated(since = "0.23.0", note = "renamed to `loads`")] -pub fn loads_bound<'py>(py: Python<'py>, data: &[u8]) -> PyResult> { - loads(py, data) -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/prelude.rs b/src/prelude.rs index d4f649f552a..62cde9a5591 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -25,9 +25,6 @@ pub use pyo3_macros::{ #[cfg(feature = "macros")] pub use crate::wrap_pyfunction; -#[cfg(feature = "macros")] -#[allow(deprecated)] -pub use crate::wrap_pyfunction_bound; pub use crate::types::any::PyAnyMethods; pub use crate::types::boolobject::PyBoolMethods; diff --git a/src/type_object.rs b/src/type_object.rs index b7cad4ab3b2..d181fff08b1 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -62,38 +62,17 @@ pub unsafe trait PyTypeInfo: Sized { } } - /// Deprecated name for [`PyTypeInfo::type_object`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTypeInfo::type_object`")] - #[inline] - fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType> { - Self::type_object(py) - } - /// Checks if `object` is an instance of this type or a subclass of this type. #[inline] fn is_type_of(object: &Bound<'_, PyAny>) -> bool { unsafe { ffi::PyObject_TypeCheck(object.as_ptr(), Self::type_object_raw(object.py())) != 0 } } - /// Deprecated name for [`PyTypeInfo::is_type_of`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTypeInfo::is_type_of`")] - #[inline] - fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool { - Self::is_type_of(object) - } - /// Checks if `object` is an instance of this type. #[inline] fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool { unsafe { ffi::Py_TYPE(object.as_ptr()) == Self::type_object_raw(object.py()) } } - - /// Deprecated name for [`PyTypeInfo::is_exact_type_of`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTypeInfo::is_exact_type_of`")] - #[inline] - fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool { - Self::is_exact_type_of(object) - } } /// Implemented by types which can be used as a concrete Python type inside `Py` smart pointers. diff --git a/src/types/any.rs b/src/types/any.rs index 7e86401ed9b..00f5594ce5d 100644 --- a/src/types/any.rs +++ b/src/types/any.rs @@ -659,12 +659,6 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed { /// This is equivalent to the Python expression `self is None`. fn is_none(&self) -> bool; - /// Returns whether the object is Ellipsis, e.g. `...`. - /// - /// This is equivalent to the Python expression `self is ...`. - #[deprecated(since = "0.23.0", note = "use `.is(py.Ellipsis())` instead")] - fn is_ellipsis(&self) -> bool; - /// Returns true if the sequence or mapping has a length of 0. /// /// This is equivalent to the Python expression `len(self) == 0`. @@ -718,13 +712,6 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed { /// ``` fn try_iter(&self) -> PyResult>; - /// Takes an object and returns an iterator for it. - /// - /// This is typically a new iterator but if the argument is an iterator, - /// this returns itself. - #[deprecated(since = "0.23.0", note = "use `try_iter` instead")] - fn iter(&self) -> PyResult>; - /// Returns the Python type object for this object's type. fn get_type(&self) -> Bound<'py, PyType>; @@ -1371,10 +1358,6 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> { unsafe { ffi::Py_None() == self.as_ptr() } } - fn is_ellipsis(&self) -> bool { - unsafe { ffi::Py_Ellipsis() == self.as_ptr() } - } - fn is_empty(&self) -> PyResult { self.len().map(|l| l == 0) } @@ -1443,10 +1426,6 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> { PyIterator::from_object(self) } - fn iter(&self) -> PyResult> { - self.try_iter() - } - fn get_type(&self) -> Bound<'py, PyType> { unsafe { PyType::from_borrowed_type_ptr(self.py(), ffi::Py_TYPE(self.as_ptr())) } } @@ -2086,22 +2065,6 @@ class SimpleClass: }) } - #[test] - #[allow(deprecated)] - fn test_is_ellipsis() { - Python::with_gil(|py| { - let v = py - .eval(ffi::c_str!("..."), None, None) - .map_err(|e| e.display(py)) - .unwrap(); - - assert!(v.is_ellipsis()); - - let not_ellipsis = 5i32.into_pyobject(py).unwrap(); - assert!(!not_ellipsis.is_ellipsis()); - }); - } - #[test] fn test_is_callable() { Python::with_gil(|py| { diff --git a/src/types/boolobject.rs b/src/types/boolobject.rs index 53043fa798c..2e7f0369de1 100644 --- a/src/types/boolobject.rs +++ b/src/types/boolobject.rs @@ -38,13 +38,6 @@ impl PyBool { .downcast_unchecked() } } - - /// Deprecated name for [`PyBool::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyBool::new`")] - #[inline] - pub fn new_bound(py: Python<'_>, val: bool) -> Borrowed<'_, '_, Self> { - Self::new(py, val) - } } /// Implementation of functionality for [`PyBool`]. diff --git a/src/types/bytearray.rs b/src/types/bytearray.rs index 094cdf3144b..c6a0683f635 100644 --- a/src/types/bytearray.rs +++ b/src/types/bytearray.rs @@ -32,13 +32,6 @@ impl PyByteArray { } } - /// Deprecated name for [`PyByteArray::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyByteArray::new`")] - #[inline] - pub fn new_bound<'py>(py: Python<'py>, src: &[u8]) -> Bound<'py, PyByteArray> { - Self::new(py, src) - } - /// Creates a new Python `bytearray` object with an `init` closure to write its contents. /// Before calling `init` the bytearray is zero-initialised. /// * If Python raises a MemoryError on the allocation, `new_with` will return @@ -84,20 +77,6 @@ impl PyByteArray { } } - /// Deprecated name for [`PyByteArray::new_with`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyByteArray::new_with`")] - #[inline] - pub fn new_bound_with( - py: Python<'_>, - len: usize, - init: F, - ) -> PyResult> - where - F: FnOnce(&mut [u8]) -> PyResult<()>, - { - Self::new_with(py, len, init) - } - /// Creates a new Python `bytearray` object from another Python object that /// implements the buffer protocol. pub fn from<'py>(src: &Bound<'py, PyAny>) -> PyResult> { @@ -107,13 +86,6 @@ impl PyByteArray { .downcast_into_unchecked() } } - - ///Deprecated name for [`PyByteArray::from`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyByteArray::from`")] - #[inline] - pub fn from_bound<'py>(src: &Bound<'py, PyAny>) -> PyResult> { - Self::from(src) - } } /// Implementation of functionality for [`PyByteArray`]. diff --git a/src/types/bytes.rs b/src/types/bytes.rs index a820ece3b45..4e2ce9c96e7 100644 --- a/src/types/bytes.rs +++ b/src/types/bytes.rs @@ -64,13 +64,6 @@ impl PyBytes { } } - /// Deprecated name for [`PyBytes::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyBytes::new`")] - #[inline] - pub fn new_bound<'p>(py: Python<'p>, s: &[u8]) -> Bound<'p, PyBytes> { - Self::new(py, s) - } - /// Creates a new Python `bytes` object with an `init` closure to write its contents. /// Before calling `init` the bytes' contents are zero-initialised. /// * If Python raises a MemoryError on the allocation, `new_with` will return @@ -114,16 +107,6 @@ impl PyBytes { } } - /// Deprecated name for [`PyBytes::new_with`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyBytes::new_with`")] - #[inline] - pub fn new_bound_with(py: Python<'_>, len: usize, init: F) -> PyResult> - where - F: FnOnce(&mut [u8]) -> PyResult<()>, - { - Self::new_with(py, len, init) - } - /// Creates a new Python byte string object from a raw pointer and length. /// /// Panics if out of memory. @@ -141,20 +124,6 @@ impl PyBytes { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyBytes::from_ptr`]. - /// - /// # Safety - /// - /// This function dereferences the raw pointer `ptr` as the - /// leading pointer of a slice of length `len`. [As with - /// `std::slice::from_raw_parts`, this is - /// unsafe](https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html#safety). - #[deprecated(since = "0.23.0", note = "renamed to `PyBytes::from_ptr`")] - #[inline] - pub unsafe fn bound_from_ptr(py: Python<'_>, ptr: *const u8, len: usize) -> Bound<'_, PyBytes> { - unsafe { Self::from_ptr(py, ptr, len) } - } } /// Implementation of functionality for [`PyBytes`]. diff --git a/src/types/capsule.rs b/src/types/capsule.rs index 5f97aeda5c5..19dde8a1cba 100644 --- a/src/types/capsule.rs +++ b/src/types/capsule.rs @@ -89,17 +89,6 @@ impl PyCapsule { Self::new_with_destructor(py, value, name, |_, _| {}) } - /// Deprecated name for [`PyCapsule::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyCapsule::new`")] - #[inline] - pub fn new_bound( - py: Python<'_>, - value: T, - name: Option, - ) -> PyResult> { - Self::new(py, value, name) - } - /// Constructs a new capsule whose contents are `value`, associated with `name`. /// /// Also provides a destructor: when the `PyCapsule` is destroyed, it will be passed the original object, @@ -139,21 +128,6 @@ impl PyCapsule { } } - /// Deprecated name for [`PyCapsule::new_with_destructor`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyCapsule::new_with_destructor`")] - #[inline] - pub fn new_bound_with_destructor< - T: 'static + Send + AssertNotZeroSized, - F: FnOnce(T, *mut c_void) + Send, - >( - py: Python<'_>, - value: T, - name: Option, - destructor: F, - ) -> PyResult> { - Self::new_with_destructor(py, value, name, destructor) - } - /// Imports an existing capsule. /// /// The `name` should match the path to the module attribute exactly in the form diff --git a/src/types/complex.rs b/src/types/complex.rs index 58651569b47..00c6c58b853 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -38,17 +38,6 @@ impl PyComplex { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyComplex::from_doubles`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyComplex::from_doubles`")] - #[inline] - pub fn from_doubles_bound( - py: Python<'_>, - real: c_double, - imag: c_double, - ) -> Bound<'_, PyComplex> { - Self::from_doubles(py, real, imag) - } } #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))] diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 0b0a7324c4b..085d41d8e65 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -177,13 +177,6 @@ pub trait PyTzInfoAccess<'py> { /// /// fn get_tzinfo(&self) -> Option>; - - /// Deprecated name for [`PyTzInfoAccess::get_tzinfo`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTzInfoAccess::get_tzinfo`")] - #[inline] - fn get_tzinfo_bound(&self) -> Option> { - self.get_tzinfo() - } } /// Bindings around `datetime.date`. @@ -212,13 +205,6 @@ impl PyDate { } } - /// Deprecated name for [`PyDate::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDate::new`")] - #[inline] - pub fn new_bound(py: Python<'_>, year: i32, month: u8, day: u8) -> PyResult> { - Self::new(py, year, month, day) - } - /// Construct a `datetime.date` from a POSIX timestamp /// /// This is equivalent to `datetime.date.fromtimestamp` @@ -234,13 +220,6 @@ impl PyDate { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyDate::from_timestamp`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDate::from_timestamp`")] - #[inline] - pub fn from_timestamp_bound(py: Python<'_>, timestamp: i64) -> PyResult> { - Self::from_timestamp(py, timestamp) - } } impl PyDateAccess for Bound<'_, PyDate> { @@ -304,34 +283,6 @@ impl PyDateTime { } } - /// Deprecated name for [`PyDateTime::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDateTime::new`")] - #[inline] - #[allow(clippy::too_many_arguments)] - pub fn new_bound<'py>( - py: Python<'py>, - year: i32, - month: u8, - day: u8, - hour: u8, - minute: u8, - second: u8, - microsecond: u32, - tzinfo: Option<&Bound<'py, PyTzInfo>>, - ) -> PyResult> { - Self::new( - py, - year, - month, - day, - hour, - minute, - second, - microsecond, - tzinfo, - ) - } - /// Alternate constructor that takes a `fold` parameter. A `true` value for this parameter /// signifies this this datetime is the later of two moments with the same representation, /// during a repeated interval. @@ -371,36 +322,6 @@ impl PyDateTime { } } - /// Deprecated name for [`PyDateTime::new_with_fold`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDateTime::new_with_fold`")] - #[inline] - #[allow(clippy::too_many_arguments)] - pub fn new_bound_with_fold<'py>( - py: Python<'py>, - year: i32, - month: u8, - day: u8, - hour: u8, - minute: u8, - second: u8, - microsecond: u32, - tzinfo: Option<&Bound<'py, PyTzInfo>>, - fold: bool, - ) -> PyResult> { - Self::new_with_fold( - py, - year, - month, - day, - hour, - minute, - second, - microsecond, - tzinfo, - fold, - ) - } - /// Construct a `datetime` object from a POSIX timestamp /// /// This is equivalent to `datetime.datetime.fromtimestamp` @@ -420,17 +341,6 @@ impl PyDateTime { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyDateTime::from_timestamp`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDateTime::from_timestamp`")] - #[inline] - pub fn from_timestamp_bound<'py>( - py: Python<'py>, - timestamp: f64, - tzinfo: Option<&Bound<'py, PyTzInfo>>, - ) -> PyResult> { - Self::from_timestamp(py, timestamp, tzinfo) - } } impl PyDateAccess for Bound<'_, PyDateTime> { @@ -543,21 +453,7 @@ impl PyTime { } } - /// Deprecated name for [`PyTime::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTime::new`")] - #[inline] - pub fn new_bound<'py>( - py: Python<'py>, - hour: u8, - minute: u8, - second: u8, - microsecond: u32, - tzinfo: Option<&Bound<'py, PyTzInfo>>, - ) -> PyResult> { - Self::new(py, hour, minute, second, microsecond, tzinfo) - } - - /// Alternate constructor that takes a `fold` argument. See [`PyDateTime::new_bound_with_fold`]. + /// Alternate constructor that takes a `fold` argument. See [`PyDateTime::new_with_fold`]. pub fn new_with_fold<'py>( py: Python<'py>, hour: u8, @@ -582,21 +478,6 @@ impl PyTime { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyTime::new_with_fold`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTime::new_with_fold`")] - #[inline] - pub fn new_bound_with_fold<'py>( - py: Python<'py>, - hour: u8, - minute: u8, - second: u8, - microsecond: u32, - tzinfo: Option<&Bound<'py, PyTzInfo>>, - fold: bool, - ) -> PyResult> { - Self::new_with_fold(py, hour, minute, second, microsecond, tzinfo, fold) - } } impl PyTimeAccess for Bound<'_, PyTime> { @@ -661,7 +542,7 @@ impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyTime> { /// [`Py`][crate::Py] or [`Bound<'py, PyTzInfo>`][Bound]. /// /// This is an abstract base class and cannot be constructed directly. -/// For concrete time zone implementations, see [`timezone_utc_bound`] and +/// For concrete time zone implementations, see [`timezone_utc`] and /// the [`zoneinfo` module](https://docs.python.org/3/library/zoneinfo.html). #[repr(transparent)] pub struct PyTzInfo(PyAny); @@ -688,13 +569,6 @@ pub fn timezone_utc(py: Python<'_>) -> Bound<'_, PyTzInfo> { } } -/// Deprecated name for [`timezone_utc`]. -#[deprecated(since = "0.23.0", note = "renamed to `timezone_utc`")] -#[inline] -pub fn timezone_utc_bound(py: Python<'_>) -> Bound<'_, PyTzInfo> { - timezone_utc(py) -} - /// Equivalent to `datetime.timezone` constructor /// /// Only used internally @@ -748,19 +622,6 @@ impl PyDelta { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyDelta::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDelta::new`")] - #[inline] - pub fn new_bound( - py: Python<'_>, - days: i32, - seconds: i32, - microseconds: i32, - normalize: bool, - ) -> PyResult> { - Self::new(py, days, seconds, microseconds, normalize) - } } impl PyDeltaAccess for Bound<'_, PyDelta> { diff --git a/src/types/dict.rs b/src/types/dict.rs index 3f5118aab6b..0ef5c477ae1 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -67,13 +67,6 @@ impl PyDict { unsafe { ffi::PyDict_New().assume_owned(py).downcast_into_unchecked() } } - /// Deprecated name for [`PyDict::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyDict::new`")] - #[inline] - pub fn new_bound(py: Python<'_>) -> Bound<'_, PyDict> { - Self::new(py) - } - /// Creates a new dictionary from the sequence given. /// /// The sequence must consist of `(PyObject, PyObject)`. This is @@ -90,14 +83,6 @@ impl PyDict { })?; Ok(dict) } - - /// Deprecated name for [`PyDict::from_sequence`]. - #[cfg(not(any(PyPy, GraalPy)))] - #[deprecated(since = "0.23.0", note = "renamed to `PyDict::from_sequence`")] - #[inline] - pub fn from_sequence_bound<'py>(seq: &Bound<'py, PyAny>) -> PyResult> { - Self::from_sequence(seq) - } } /// Implementation of functionality for [`PyDict`]. @@ -776,13 +761,6 @@ pub trait IntoPyDict<'py>: Sized { /// Converts self into a `PyDict` object pointer. Whether pointer owned or borrowed /// depends on implementation. fn into_py_dict(self, py: Python<'py>) -> PyResult>; - - /// Deprecated name for [`IntoPyDict::into_py_dict`]. - #[deprecated(since = "0.23.0", note = "renamed to `IntoPyDict::into_py_dict`")] - #[inline] - fn into_py_dict_bound(self, py: Python<'py>) -> Bound<'py, PyDict> { - self.into_py_dict(py).unwrap() - } } impl<'py, T, I> IntoPyDict<'py> for I diff --git a/src/types/ellipsis.rs b/src/types/ellipsis.rs index ee5898c9013..19cb2d2dca9 100644 --- a/src/types/ellipsis.rs +++ b/src/types/ellipsis.rs @@ -18,13 +18,6 @@ impl PyEllipsis { pub fn get(py: Python<'_>) -> Borrowed<'_, '_, PyEllipsis> { unsafe { ffi::Py_Ellipsis().assume_borrowed(py).downcast_unchecked() } } - - /// Deprecated name for [`PyEllipsis::get`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyEllipsis::get`")] - #[inline] - pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyEllipsis> { - Self::get(py) - } } unsafe impl PyTypeInfo for PyEllipsis { diff --git a/src/types/float.rs b/src/types/float.rs index 3c2d6643d18..89001495227 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -43,13 +43,6 @@ impl PyFloat { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyFloat::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyFloat::new`")] - #[inline] - pub fn new_bound(py: Python<'_>, val: c_double) -> Bound<'_, PyFloat> { - Self::new(py, val) - } } /// Implementation of functionality for [`PyFloat`]. diff --git a/src/types/frozenset.rs b/src/types/frozenset.rs index df22560cd8e..edde7ca146e 100644 --- a/src/types/frozenset.rs +++ b/src/types/frozenset.rs @@ -49,13 +49,6 @@ impl<'py> PyFrozenSetBuilder<'py> { pub fn finalize(self) -> Bound<'py, PyFrozenSet> { self.py_frozen_set } - - /// Deprecated name for [`PyFrozenSetBuilder::finalize`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyFrozenSetBuilder::finalize`")] - #[inline] - pub fn finalize_bound(self) -> Bound<'py, PyFrozenSet> { - self.finalize() - } } /// Represents a Python `frozenset`. @@ -100,17 +93,6 @@ impl PyFrozenSet { try_new_from_iter(py, elements) } - /// Deprecated name for [`PyFrozenSet::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyFrozenSet::new`")] - #[allow(deprecated)] - #[inline] - pub fn new_bound<'a, 'p, T: crate::ToPyObject + 'a>( - py: Python<'p>, - elements: impl IntoIterator, - ) -> PyResult> { - Self::new(py, elements.into_iter().map(|e| e.to_object(py))) - } - /// Creates a new empty frozen set pub fn empty(py: Python<'_>) -> PyResult> { unsafe { @@ -119,13 +101,6 @@ impl PyFrozenSet { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyFrozenSet::empty`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyFrozenSet::empty`")] - #[inline] - pub fn empty_bound(py: Python<'_>) -> PyResult> { - Self::empty(py) - } } /// Implementation of functionality for [`PyFrozenSet`]. diff --git a/src/types/function.rs b/src/types/function.rs index 2f4da950b0a..1747c87038e 100644 --- a/src/types/function.rs +++ b/src/types/function.rs @@ -39,19 +39,6 @@ impl PyCFunction { ) } - /// Deprecated name for [`PyCFunction::new_with_keywords`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new_with_keywords`")] - #[inline] - pub fn new_with_keywords_bound<'py>( - py: Python<'py>, - fun: ffi::PyCFunctionWithKeywords, - name: &'static CStr, - doc: &'static CStr, - module: Option<&Bound<'py, PyModule>>, - ) -> PyResult> { - Self::new_with_keywords(py, fun, name, doc, module) - } - /// Create a new built-in function which takes no arguments. /// /// To create `name` and `doc` static strings on Rust versions older than 1.77 (which added c"" literals), @@ -66,19 +53,6 @@ impl PyCFunction { Self::internal_new(py, &PyMethodDef::noargs(name, fun, doc), module) } - /// Deprecated name for [`PyCFunction::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new`")] - #[inline] - pub fn new_bound<'py>( - py: Python<'py>, - fun: ffi::PyCFunction, - name: &'static CStr, - doc: &'static CStr, - module: Option<&Bound<'py, PyModule>>, - ) -> PyResult> { - Self::new(py, fun, name, doc, module) - } - /// Create a new function from a closure. /// /// # Examples @@ -131,22 +105,6 @@ impl PyCFunction { } } - /// Deprecated name for [`PyCFunction::new_closure`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyCFunction::new_closure`")] - #[inline] - pub fn new_closure_bound<'py, F, R>( - py: Python<'py>, - name: Option<&'static CStr>, - doc: Option<&'static CStr>, - closure: F, - ) -> PyResult> - where - F: Fn(&Bound<'_, PyTuple>, Option<&Bound<'_, PyDict>>) -> R + Send + 'static, - for<'p> R: crate::impl_::callback::IntoPyCallbackOutput<'p, *mut ffi::PyObject>, - { - Self::new_closure(py, name, doc, closure) - } - #[doc(hidden)] pub fn internal_new<'py>( py: Python<'py>, diff --git a/src/types/iterator.rs b/src/types/iterator.rs index f6709a8f234..6731fff2c48 100644 --- a/src/types/iterator.rs +++ b/src/types/iterator.rs @@ -34,7 +34,7 @@ pyobject_native_type_named!(PyIterator); impl PyIterator { /// Builds an iterator for an iterable Python object; the equivalent of calling `iter(obj)` in Python. /// - /// Usually it is more convenient to write [`obj.iter()`][crate::types::any::PyAnyMethods::iter], + /// Usually it is more convenient to write [`obj.try_iter()`][crate::types::any::PyAnyMethods::try_iter], /// which is a more concise way of calling this function. pub fn from_object<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { unsafe { @@ -43,13 +43,6 @@ impl PyIterator { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyIterator::from_object`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyIterator::from_object`")] - #[inline] - pub fn from_bound_object<'py>(obj: &Bound<'py, PyAny>) -> PyResult> { - Self::from_object(obj) - } } #[derive(Debug)] diff --git a/src/types/list.rs b/src/types/list.rs index bd770aaeca7..9612aa00cda 100644 --- a/src/types/list.rs +++ b/src/types/list.rs @@ -110,22 +110,6 @@ impl PyList { try_new_from_iter(py, iter) } - /// Deprecated name for [`PyList::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyList::new`")] - #[allow(deprecated)] - #[inline] - #[track_caller] - pub fn new_bound( - py: Python<'_>, - elements: impl IntoIterator, - ) -> Bound<'_, PyList> - where - T: crate::ToPyObject, - U: ExactSizeIterator, - { - Self::new(py, elements.into_iter().map(|e| e.to_object(py))).unwrap() - } - /// Constructs a new empty list. pub fn empty(py: Python<'_>) -> Bound<'_, PyList> { unsafe { @@ -134,13 +118,6 @@ impl PyList { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyList::empty`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyList::empty`")] - #[inline] - pub fn empty_bound(py: Python<'_>) -> Bound<'_, PyList> { - Self::empty(py) - } } /// Implementation of functionality for [`PyList`]. diff --git a/src/types/memoryview.rs b/src/types/memoryview.rs index 81acc5cbb2a..31bdcd47d65 100644 --- a/src/types/memoryview.rs +++ b/src/types/memoryview.rs @@ -22,13 +22,6 @@ impl PyMemoryView { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyMemoryView::from`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyMemoryView::from`")] - #[inline] - pub fn from_bound<'py>(src: &Bound<'py, PyAny>) -> PyResult> { - Self::from(src) - } } impl<'py> TryFrom<&Bound<'py, PyAny>> for Bound<'py, PyMemoryView> { diff --git a/src/types/mod.rs b/src/types/mod.rs index 637d07d72b6..c24856e2cf1 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -11,8 +11,8 @@ pub use self::complex::{PyComplex, PyComplexMethods}; #[cfg(not(Py_LIMITED_API))] #[allow(deprecated)] pub use self::datetime::{ - timezone_utc, timezone_utc_bound, PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, - PyTime, PyTimeAccess, PyTzInfo, PyTzInfoAccess, + timezone_utc, PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, + PyTzInfo, PyTzInfoAccess, }; pub use self::dict::{IntoPyDict, PyDict, PyDictMethods}; #[cfg(not(any(PyPy, GraalPy)))] @@ -35,8 +35,7 @@ pub use self::memoryview::PyMemoryView; pub use self::module::{PyModule, PyModuleMethods}; pub use self::none::PyNone; pub use self::notimplemented::PyNotImplemented; -#[allow(deprecated)] -pub use self::num::{PyInt, PyLong}; +pub use self::num::PyInt; #[cfg(not(any(PyPy, GraalPy)))] pub use self::pysuper::PySuper; pub use self::sequence::{PySequence, PySequenceMethods}; @@ -44,8 +43,7 @@ pub use self::set::{PySet, PySetMethods}; pub use self::slice::{PySlice, PySliceIndices, PySliceMethods}; #[cfg(not(Py_LIMITED_API))] pub use self::string::PyStringData; -#[allow(deprecated)] -pub use self::string::{PyString, PyStringMethods, PyUnicode}; +pub use self::string::{PyString, PyStringMethods}; pub use self::traceback::{PyTraceback, PyTracebackMethods}; pub use self::tuple::{PyTuple, PyTupleMethods}; pub use self::typeobject::{PyType, PyTypeMethods}; diff --git a/src/types/module.rs b/src/types/module.rs index 99dc1be233b..d6b7f228c58 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -7,10 +7,9 @@ use crate::types::{ any::PyAnyMethods, list::PyListMethods, PyAny, PyCFunction, PyDict, PyList, PyString, }; use crate::{ - exceptions, ffi, Borrowed, Bound, BoundObject, IntoPyObject, IntoPyObjectExt, Py, PyObject, - Python, + exceptions, ffi, Borrowed, Bound, BoundObject, IntoPyObject, IntoPyObjectExt, PyObject, Python, }; -use std::ffi::{CStr, CString}; +use std::ffi::CStr; #[cfg(all(not(Py_LIMITED_API), Py_GIL_DISABLED))] use std::os::raw::c_int; use std::str; @@ -59,13 +58,6 @@ impl PyModule { } } - /// Deprecated name for [`PyModule::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyModule::new`")] - #[inline] - pub fn new_bound<'py>(py: Python<'py>, name: &str) -> PyResult> { - Self::new(py, name) - } - /// Imports the Python module with the specified name. /// /// # Examples @@ -99,17 +91,6 @@ impl PyModule { } } - /// Deprecated name for [`PyModule::import`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyModule::import`")] - #[allow(deprecated)] - #[inline] - pub fn import_bound(py: Python<'_>, name: N) -> PyResult> - where - N: crate::IntoPy>, - { - Self::import(py, name.into_py(py)) - } - /// Creates and loads a module named `module_name`, /// containing the Python code passed to `code` /// and pretending to live at `file_name`. @@ -127,7 +108,7 @@ impl PyModule { /// Returns `PyErr` if: /// - `code` is not syntactically correct Python. /// - Any Python exceptions are raised while initializing the module. - /// - Any of the arguments cannot be converted to [`CString`]s. + /// - Any of the arguments cannot be converted to [`CString`][std::ffi::CString]s. /// /// # Example: bundle in a file at compile time with [`include_str!`][std::include_str]: /// @@ -182,22 +163,6 @@ impl PyModule { .downcast_into() } } - - /// Deprecated name for [`PyModule::from_code`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyModule::from_code`")] - #[inline] - pub fn from_code_bound<'py>( - py: Python<'py>, - code: &str, - file_name: &str, - module_name: &str, - ) -> PyResult> { - let data = CString::new(code)?; - let filename = CString::new(file_name)?; - let module = CString::new(module_name)?; - - Self::from_code(py, data.as_c_str(), filename.as_c_str(), module.as_c_str()) - } } /// Implementation of functionality for [`PyModule`]. diff --git a/src/types/none.rs b/src/types/none.rs index 1ec12d3f5b0..da8ef1aa51b 100644 --- a/src/types/none.rs +++ b/src/types/none.rs @@ -18,13 +18,6 @@ impl PyNone { pub fn get(py: Python<'_>) -> Borrowed<'_, '_, PyNone> { unsafe { ffi::Py_None().assume_borrowed(py).downcast_unchecked() } } - - /// Deprecated name for [`PyNone::get`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyNone::get`")] - #[inline] - pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNone> { - Self::get(py) - } } unsafe impl PyTypeInfo for PyNone { diff --git a/src/types/notimplemented.rs b/src/types/notimplemented.rs index d93ab466d2d..040cc19db61 100644 --- a/src/types/notimplemented.rs +++ b/src/types/notimplemented.rs @@ -22,13 +22,6 @@ impl PyNotImplemented { .downcast_unchecked() } } - - /// Deprecated name for [`PyNotImplemented::get`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyNotImplemented::get`")] - #[inline] - pub fn get_bound(py: Python<'_>) -> Borrowed<'_, '_, PyNotImplemented> { - Self::get(py) - } } unsafe impl PyTypeInfo for PyNotImplemented { diff --git a/src/types/num.rs b/src/types/num.rs index 8de116a470f..38874f29aba 100644 --- a/src/types/num.rs +++ b/src/types/num.rs @@ -16,10 +16,6 @@ pub struct PyInt(PyAny); pyobject_native_type_core!(PyInt, pyobject_native_static_type_object!(ffi::PyLong_Type), #checkfunction=ffi::PyLong_Check); -/// Deprecated alias for [`PyInt`]. -#[deprecated(since = "0.23.0", note = "use `PyInt` instead")] -pub type PyLong = PyInt; - impl PyInt { /// Creates a new Python int object. /// diff --git a/src/types/pysuper.rs b/src/types/pysuper.rs index 81db8cea869..ac04d78cc98 100644 --- a/src/types/pysuper.rs +++ b/src/types/pysuper.rs @@ -66,14 +66,4 @@ impl PySuper { unsafe { any.downcast_into_unchecked() } }) } - - /// Deprecated name for [`PySuper::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PySuper::new`")] - #[inline] - pub fn new_bound<'py>( - ty: &Bound<'py, PyType>, - obj: &Bound<'py, PyAny>, - ) -> PyResult> { - Self::new(ty, obj) - } } diff --git a/src/types/set.rs b/src/types/set.rs index ddaddbfe5ed..93c251d460f 100644 --- a/src/types/set.rs +++ b/src/types/set.rs @@ -54,17 +54,6 @@ impl PySet { try_new_from_iter(py, elements) } - /// Deprecated name for [`PySet::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PySet::new`")] - #[allow(deprecated)] - #[inline] - pub fn new_bound<'a, 'p, T: ToPyObject + 'a>( - py: Python<'p>, - elements: impl IntoIterator, - ) -> PyResult> { - Self::new(py, elements.into_iter().map(|e| e.to_object(py))) - } - /// Creates a new empty set. pub fn empty(py: Python<'_>) -> PyResult> { unsafe { @@ -73,13 +62,6 @@ impl PySet { .downcast_into_unchecked() } } - - /// Deprecated name for [`PySet::empty`]. - #[deprecated(since = "0.23.0", note = "renamed to `PySet::empty`")] - #[inline] - pub fn empty_bound(py: Python<'_>) -> PyResult> { - Self::empty(py) - } } /// Implementation of functionality for [`PySet`]. diff --git a/src/types/slice.rs b/src/types/slice.rs index 9ca2aa4ec43..b74a228aae3 100644 --- a/src/types/slice.rs +++ b/src/types/slice.rs @@ -69,13 +69,6 @@ impl PySlice { } } - /// Deprecated name for [`PySlice::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PySlice::new`")] - #[inline] - pub fn new_bound(py: Python<'_>, start: isize, stop: isize, step: isize) -> Bound<'_, PySlice> { - Self::new(py, start, stop, step) - } - /// Constructs a new full slice that is equivalent to `::`. pub fn full(py: Python<'_>) -> Bound<'_, PySlice> { unsafe { @@ -84,13 +77,6 @@ impl PySlice { .downcast_into_unchecked() } } - - /// Deprecated name for [`PySlice::full`]. - #[deprecated(since = "0.23.0", note = "renamed to `PySlice::full`")] - #[inline] - pub fn full_bound(py: Python<'_>) -> Bound<'_, PySlice> { - Self::full(py) - } } /// Implementation of functionality for [`PySlice`]. diff --git a/src/types/string.rs b/src/types/string.rs index a389f0df234..f7a724b9fce 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -13,10 +13,6 @@ use std::borrow::Cow; use std::ffi::CString; use std::str; -/// Deprecated alias for [`PyString`]. -#[deprecated(since = "0.23.0", note = "use `PyString` instead")] -pub type PyUnicode = PyString; - /// Represents raw data backing a Python `str`. /// /// Python internally stores strings in various representations. This enumeration @@ -175,19 +171,12 @@ impl PyString { } } - /// Deprecated name for [`PyString::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyString::new`")] - #[inline] - pub fn new_bound<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> { - Self::new(py, s) - } - /// Intern the given string /// /// This will return a reference to the same Python string object if called repeatedly with the same string. /// - /// Note that while this is more memory efficient than [`PyString::new_bound`], it unconditionally allocates a - /// temporary Python string object and is thereby slower than [`PyString::new_bound`]. + /// Note that while this is more memory efficient than [`PyString::new`], it unconditionally allocates a + /// temporary Python string object and is thereby slower than [`PyString::new`]. /// /// Panics if out of memory. pub fn intern<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> { @@ -202,13 +191,6 @@ impl PyString { } } - /// Deprecated name for [`PyString::intern`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyString::intern`")] - #[inline] - pub fn intern_bound<'py>(py: Python<'py>, s: &str) -> Bound<'py, PyString> { - Self::intern(py, s) - } - /// Attempts to create a Python string from a Python [bytes-like object]. /// /// [bytes-like object]: (https://docs.python.org/3/glossary.html#term-bytes-like-object). @@ -229,17 +211,6 @@ impl PyString { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyString::from_object`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyString::from_object`")] - #[inline] - pub fn from_object_bound<'py>( - src: &Bound<'py, PyAny>, - encoding: &str, - errors: &str, - ) -> PyResult> { - Self::from_object(src, encoding, errors) - } } /// Implementation of functionality for [`PyString`]. diff --git a/src/types/tuple.rs b/src/types/tuple.rs index a35f5805c15..c412a81a752 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -104,22 +104,6 @@ impl PyTuple { try_new_from_iter(py, elements) } - /// Deprecated name for [`PyTuple::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTuple::new`")] - #[allow(deprecated)] - #[track_caller] - #[inline] - pub fn new_bound( - py: Python<'_>, - elements: impl IntoIterator, - ) -> Bound<'_, PyTuple> - where - T: ToPyObject, - U: ExactSizeIterator, - { - PyTuple::new(py, elements.into_iter().map(|e| e.to_object(py))).unwrap() - } - /// Constructs an empty tuple (on the Python side, a singleton object). pub fn empty(py: Python<'_>) -> Bound<'_, PyTuple> { unsafe { @@ -128,13 +112,6 @@ impl PyTuple { .downcast_into_unchecked() } } - - /// Deprecated name for [`PyTuple::empty`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyTuple::empty`")] - #[inline] - pub fn empty_bound(py: Python<'_>) -> Bound<'_, PyTuple> { - PyTuple::empty(py) - } } /// Implementation of functionality for [`PyTuple`]. diff --git a/src/types/typeobject.rs b/src/types/typeobject.rs index 7ab3690b90b..194755fc5a3 100644 --- a/src/types/typeobject.rs +++ b/src/types/typeobject.rs @@ -27,13 +27,6 @@ impl PyType { T::type_object(py) } - /// Deprecated name for [`PyType::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyType::new`")] - #[inline] - pub fn new_bound(py: Python<'_>) -> Bound<'_, PyType> { - Self::new::(py) - } - /// Converts the given FFI pointer into `Bound`, to use in safe code. /// /// The function creates a new reference from the given pointer, and returns diff --git a/src/types/weakref/anyref.rs b/src/types/weakref/anyref.rs index 741a638c295..cea930b7204 100644 --- a/src/types/weakref/anyref.rs +++ b/src/types/weakref/anyref.rs @@ -1,11 +1,8 @@ use crate::err::PyResult; use crate::ffi_ptr_ext::FfiPtrExt; use crate::type_object::{PyTypeCheck, PyTypeInfo}; -use crate::types::{ - any::{PyAny, PyAnyMethods}, - PyNone, -}; -use crate::{ffi, Bound, Python}; +use crate::types::any::{PyAny, PyAnyMethods}; +use crate::{ffi, Bound}; /// Represents any Python `weakref` reference. /// @@ -321,74 +318,6 @@ pub trait PyWeakrefMethods<'py>: crate::sealed::Sealed { /// [`weakref.ReferenceType`]: https://docs.python.org/3/library/weakref.html#weakref.ReferenceType /// [`weakref.ref`]: https://docs.python.org/3/library/weakref.html#weakref.ref fn upgrade(&self) -> Option>; - - /// Retrieve to a Bound object pointed to by the weakref. - /// - /// This function returns `Bound<'py, PyAny>`, which is either the object if it still exists, otherwise it will refer to [`PyNone`](crate::types::PyNone). - /// - /// This function gets the optional target of this [`weakref.ReferenceType`] (result of calling [`weakref.ref`]). - /// It produces similar results to using [`PyWeakref_GetRef`] in the C api. - /// - /// # Example - #[cfg_attr( - not(all(feature = "macros", not(all(Py_LIMITED_API, not(Py_3_9))))), - doc = "```rust,ignore" - )] - #[cfg_attr( - all(feature = "macros", not(all(Py_LIMITED_API, not(Py_3_9)))), - doc = "```rust" - )] - /// #![allow(deprecated)] - /// use pyo3::prelude::*; - /// use pyo3::types::PyWeakrefReference; - /// - /// #[pyclass(weakref)] - /// struct Foo { /* fields omitted */ } - /// - /// fn get_class(reference: Borrowed<'_, '_, PyWeakrefReference>) -> PyResult { - /// reference - /// .get_object() - /// .getattr("__class__")? - /// .repr() - /// .map(|repr| repr.to_string()) - /// } - /// - /// # fn main() -> PyResult<()> { - /// Python::with_gil(|py| { - /// let object = Bound::new(py, Foo{})?; - /// let reference = PyWeakrefReference::new(&object)?; - /// - /// assert_eq!( - /// get_class(reference.as_borrowed())?, - /// "" - /// ); - /// - /// drop(object); - /// - /// assert_eq!(get_class(reference.as_borrowed())?, ""); - /// - /// Ok(()) - /// }) - /// # } - /// ``` - /// - /// # Panics - /// This function panics is the current object is invalid. - /// If used propperly this is never the case. (NonNull and actually a weakref type) - /// - /// [`PyWeakref_GetRef`]: https://docs.python.org/3/c-api/weakref.html#c.PyWeakref_GetRef - /// [`weakref.ReferenceType`]: https://docs.python.org/3/library/weakref.html#weakref.ReferenceType - /// [`weakref.ref`]: https://docs.python.org/3/library/weakref.html#weakref.ref - #[deprecated(since = "0.23.0", note = "Use `upgrade` instead")] - fn get_object(&self) -> Bound<'py, PyAny> { - self.upgrade().unwrap_or_else(|| { - // Safety: upgrade() returns `Bound<'py, PyAny>` with a lifetime `'py` if it exists, we - // can safely assume the same lifetime here. - PyNone::get(unsafe { Python::assume_gil_acquired() }) - .to_owned() - .into_any() - }) - } } impl<'py> PyWeakrefMethods<'py> for Bound<'py, PyWeakref> { @@ -545,40 +474,6 @@ mod tests { inner(new_reference, true)?; inner(new_proxy, false) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - fn inner( - create_reference: impl for<'py> FnOnce( - &Bound<'py, PyAny>, - ) - -> PyResult>, - call_retrievable: bool, - ) -> PyResult<()> { - let not_call_retrievable = !call_retrievable; - - Python::with_gil(|py| { - let class = get_type(py)?; - let object = class.call0()?; - let reference = create_reference(&object)?; - - assert!(not_call_retrievable || reference.call0()?.is(&object)); - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(not_call_retrievable || reference.call0()?.is(&reference.get_object())); - assert!(not_call_retrievable || reference.call0()?.is_none()); - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } - - inner(new_reference, true)?; - inner(new_proxy, false) - } } // under 'abi3-py37' and 'abi3-py38' PyClass cannot be weakreferencable. @@ -697,38 +592,5 @@ mod tests { inner(new_reference, true)?; inner(new_proxy, false) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - fn inner( - create_reference: impl for<'py> FnOnce( - &Bound<'py, PyAny>, - ) - -> PyResult>, - call_retrievable: bool, - ) -> PyResult<()> { - let not_call_retrievable = !call_retrievable; - - Python::with_gil(|py| { - let object = Py::new(py, WeakrefablePyClass {})?; - let reference = create_reference(object.bind(py))?; - - assert!(not_call_retrievable || reference.call0()?.is(&object)); - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(not_call_retrievable || reference.call0()?.is(&reference.get_object())); - assert!(not_call_retrievable || reference.call0()?.is_none()); - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } - - inner(new_reference, true)?; - inner(new_proxy, false) - } } } diff --git a/src/types/weakref/proxy.rs b/src/types/weakref/proxy.rs index 5334f0341f1..563c5b0982c 100644 --- a/src/types/weakref/proxy.rs +++ b/src/types/weakref/proxy.rs @@ -80,13 +80,6 @@ impl PyWeakrefProxy { } } - /// Deprecated name for [`PyWeakrefProxy::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyWeakrefProxy::new`")] - #[inline] - pub fn new_bound<'py>(object: &Bound<'py, PyAny>) -> PyResult> { - Self::new(object) - } - /// Constructs a new Weak Reference (`weakref.proxy`/`weakref.ProxyType`/`weakref.CallableProxyType`) for the given object with a callback. /// /// Returns a `TypeError` if `object` is not weak referenceable (Most native types and PyClasses without `weakref` flag) or if the `callback` is not callable or None. @@ -172,20 +165,6 @@ impl PyWeakrefProxy { .as_borrowed(), ) } - - /// Deprecated name for [`PyWeakrefProxy::new_with`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyWeakrefProxy::new_with`")] - #[allow(deprecated)] - #[inline] - pub fn new_bound_with<'py, C>( - object: &Bound<'py, PyAny>, - callback: C, - ) -> PyResult> - where - C: crate::ToPyObject, - { - Self::new_with(object, callback.to_object(object.py())) - } } impl<'py> PyWeakrefMethods<'py> for Bound<'py, PyWeakrefProxy> { @@ -579,23 +558,6 @@ mod tests { Ok(()) }) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - Python::with_gil(|py| { - let object = Py::new(py, WeakrefablePyClass {})?; - let reference = PyWeakrefProxy::new(object.bind(py))?; - - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } } } @@ -753,24 +715,6 @@ mod tests { Ok(()) }) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - Python::with_gil(|py| { - let class = get_type(py)?; - let object = class.call0()?; - let reference = PyWeakrefProxy::new(&object)?; - - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } } // under 'abi3-py37' and 'abi3-py38' PyClass cannot be weakreferencable. @@ -913,23 +857,6 @@ mod tests { Ok(()) }) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - Python::with_gil(|py| { - let object = Py::new(py, WeakrefablePyClass {})?; - let reference = PyWeakrefProxy::new(object.bind(py))?; - - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } } } } diff --git a/src/types/weakref/reference.rs b/src/types/weakref/reference.rs index edabb6da935..334f136aa33 100644 --- a/src/types/weakref/reference.rs +++ b/src/types/weakref/reference.rs @@ -90,13 +90,6 @@ impl PyWeakrefReference { } } - /// Deprecated name for [`PyWeakrefReference::new`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyWeakrefReference::new`")] - #[inline] - pub fn new_bound<'py>(object: &Bound<'py, PyAny>) -> PyResult> { - Self::new(object) - } - /// Constructs a new Weak Reference (`weakref.ref`/`weakref.ReferenceType`) for the given object with a callback. /// /// Returns a `TypeError` if `object` is not weak referenceable (Most native types and PyClasses without `weakref` flag) or if the `callback` is not callable or None. @@ -181,20 +174,6 @@ impl PyWeakrefReference { .as_borrowed(), ) } - - /// Deprecated name for [`PyWeakrefReference::new_with`]. - #[deprecated(since = "0.23.0", note = "renamed to `PyWeakrefReference::new_with`")] - #[allow(deprecated)] - #[inline] - pub fn new_bound_with<'py, C>( - object: &Bound<'py, PyAny>, - callback: C, - ) -> PyResult> - where - C: crate::ToPyObject, - { - Self::new_with(object, callback.to_object(object.py())) - } } impl<'py> PyWeakrefMethods<'py> for Bound<'py, PyWeakrefReference> { @@ -392,27 +371,6 @@ mod tests { Ok(()) }) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - Python::with_gil(|py| { - let class = get_type(py)?; - let object = class.call0()?; - let reference = PyWeakrefReference::new(&object)?; - - assert!(reference.call0()?.is(&object)); - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(reference.call0()?.is(&reference.get_object())); - assert!(reference.call0()?.is_none()); - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } } // under 'abi3-py37' and 'abi3-py38' PyClass cannot be weakreferencable. @@ -537,25 +495,5 @@ mod tests { Ok(()) }) } - - #[test] - #[allow(deprecated)] - fn test_weakref_get_object() -> PyResult<()> { - Python::with_gil(|py| { - let object = Py::new(py, WeakrefablePyClass {})?; - let reference = PyWeakrefReference::new(object.bind(py))?; - - assert!(reference.call0()?.is(&object)); - assert!(reference.get_object().is(&object)); - - drop(object); - - assert!(reference.call0()?.is(&reference.get_object())); - assert!(reference.call0()?.is_none()); - assert!(reference.get_object().is_none()); - - Ok(()) - }) - } } } From 9641e434d2408a774251961be4334f0851f1dbde Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 17 Mar 2025 21:37:11 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Lily Foote --- pyo3-benches/benches/bench_list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyo3-benches/benches/bench_list.rs b/pyo3-benches/benches/bench_list.rs index bb47d824c4e..f6df0cc4315 100644 --- a/pyo3-benches/benches/bench_list.rs +++ b/pyo3-benches/benches/bench_list.rs @@ -42,7 +42,7 @@ fn list_get_item(b: &mut Bencher<'_>) { fn list_nth(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50; - let list = PyList::new(py, 0..LEN); + let list = PyList::new(py, 0..LEN).unwrap(); let mut sum = 0; b.iter(|| { for i in 0..LEN { @@ -55,7 +55,7 @@ fn list_nth(b: &mut Bencher<'_>) { fn list_nth_back(b: &mut Bencher<'_>) { Python::with_gil(|py| { const LEN: usize = 50; - let list = PyList::new(py, 0..LEN); + let list = PyList::new(py, 0..LEN).unwrap(); let mut sum = 0; b.iter(|| { for i in 0..LEN { From 351622b19d7e589a4f9c94fe3e908635ea683507 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 28 Mar 2025 21:06:16 +0000 Subject: [PATCH 3/3] bump version to 0.25.0-dev --- Cargo.toml | 8 ++++---- pyo3-build-config/Cargo.toml | 2 +- pyo3-ffi/Cargo.toml | 4 ++-- pyo3-macros-backend/Cargo.toml | 6 +++--- pyo3-macros/Cargo.toml | 4 ++-- pyproject.toml | 2 +- tests/ui/reject_generics.stderr | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 84c6daba30e..c734f9fadd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3" -version = "0.24.0" +version = "0.25.0-dev" description = "Bindings to Python interpreter" authors = ["PyO3 Project and Contributors "] readme = "README.md" @@ -21,10 +21,10 @@ memoffset = "0.9" once_cell = "1.13" # ffi bindings to the python interpreter, split into a separate crate so they can be used independently -pyo3-ffi = { path = "pyo3-ffi", version = "=0.24.0" } +pyo3-ffi = { path = "pyo3-ffi", version = "=0.25.0-dev" } # support crates for macros feature -pyo3-macros = { path = "pyo3-macros", version = "=0.24.0", optional = true } +pyo3-macros = { path = "pyo3-macros", version = "=0.25.0-dev", optional = true } indoc = { version = "2.0.1", optional = true } unindent = { version = "0.2.1", optional = true } @@ -68,7 +68,7 @@ static_assertions = "1.1.0" uuid = { version = "1.10.0", features = ["v4"] } [build-dependencies] -pyo3-build-config = { path = "pyo3-build-config", version = "=0.24.0", features = ["resolve-config"] } +pyo3-build-config = { path = "pyo3-build-config", version = "=0.25.0-dev", features = ["resolve-config"] } [features] default = ["macros"] diff --git a/pyo3-build-config/Cargo.toml b/pyo3-build-config/Cargo.toml index b8030cc4304..86456e33cb5 100644 --- a/pyo3-build-config/Cargo.toml +++ b/pyo3-build-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-build-config" -version = "0.24.0" +version = "0.25.0-dev" description = "Build configuration for the PyO3 ecosystem" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] diff --git a/pyo3-ffi/Cargo.toml b/pyo3-ffi/Cargo.toml index 16c8a3374cd..8b75c978c2e 100644 --- a/pyo3-ffi/Cargo.toml +++ b/pyo3-ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-ffi" -version = "0.24.0" +version = "0.25.0-dev" description = "Python-API bindings for the PyO3 ecosystem" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -43,7 +43,7 @@ generate-import-lib = ["pyo3-build-config/python3-dll-a"] paste = "1" [build-dependencies] -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.24.0", features = ["resolve-config"] } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.25.0-dev", features = ["resolve-config"] } [lints] workspace = true diff --git a/pyo3-macros-backend/Cargo.toml b/pyo3-macros-backend/Cargo.toml index 91e0009f9f6..6bd69a1b58f 100644 --- a/pyo3-macros-backend/Cargo.toml +++ b/pyo3-macros-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-macros-backend" -version = "0.24.0" +version = "0.25.0-dev" description = "Code generation for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -17,7 +17,7 @@ rust-version = "1.63" [dependencies] heck = "0.5" proc-macro2 = { version = "1.0.60", default-features = false } -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.24.0", features = ["resolve-config"] } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.25.0-dev", features = ["resolve-config"] } quote = { version = "1", default-features = false } [dependencies.syn] @@ -26,7 +26,7 @@ default-features = false features = ["derive", "parsing", "printing", "clone-impls", "full", "extra-traits"] [build-dependencies] -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.24.0" } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.25.0-dev" } [lints] workspace = true diff --git a/pyo3-macros/Cargo.toml b/pyo3-macros/Cargo.toml index 25821b84e81..4d91de26df9 100644 --- a/pyo3-macros/Cargo.toml +++ b/pyo3-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-macros" -version = "0.24.0" +version = "0.25.0-dev" description = "Proc macros for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -22,7 +22,7 @@ experimental-async = ["pyo3-macros-backend/experimental-async"] proc-macro2 = { version = "1.0.60", default-features = false } quote = "1" syn = { version = "2", features = ["full", "extra-traits"] } -pyo3-macros-backend = { path = "../pyo3-macros-backend", version = "=0.24.0" } +pyo3-macros-backend = { path = "../pyo3-macros-backend", version = "=0.25.0-dev" } [lints] workspace = true diff --git a/pyproject.toml b/pyproject.toml index d757c927f4f..1ff0f0332de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [tool.towncrier] filename = "CHANGELOG.md" -version = "0.24.0" +version = "0.25.0-dev" start_string = "\n" template = ".towncrier.template.md" title_format = "## [{version}] - {project_date}" diff --git a/tests/ui/reject_generics.stderr b/tests/ui/reject_generics.stderr index 9cb7e6e2068..fed5d48937e 100644 --- a/tests/ui/reject_generics.stderr +++ b/tests/ui/reject_generics.stderr @@ -1,10 +1,10 @@ -error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.24.0/class.html#no-generic-parameters +error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.25.0-dev/class.html#no-generic-parameters --> tests/ui/reject_generics.rs:4:25 | 4 | struct ClassWithGenerics { | ^ -error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.24.0/class.html#no-lifetime-parameters +error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.25.0-dev/class.html#no-lifetime-parameters --> tests/ui/reject_generics.rs:9:27 | 9 | struct ClassWithLifetimes<'a> {