Skip to content

Commit ef94e03

Browse files
committed
feature gate deprecated more APIs for Py
1 parent f3c7b90 commit ef94e03

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

src/err/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl PyErr {
724724
///
725725
/// The `category` should be one of the `Warning` classes available in
726726
/// [`pyo3::exceptions`](crate::exceptions), or a subclass. The Python
727-
/// object can be retrieved using [`Python::get_type()`].
727+
/// object can be retrieved using [`Python::get_type_bound()`].
728728
///
729729
/// Example:
730730
/// ```rust

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
///
33
/// # Panics
44
///
5-
/// This macro internally calls [`Python::run`](crate::Python::run) and panics
5+
/// This macro internally calls [`Python::run_bound`](crate::Python::run_bound) and panics
66
/// if it returns `Err`, after printing the error to stdout.
77
///
8-
/// If you need to handle failures, please use [`Python::run`](crate::marker::Python::run) instead.
8+
/// If you need to handle failures, please use [`Python::run_bound`](crate::marker::Python::run_bound) instead.
99
///
1010
/// # Examples
1111
/// ```

src/marker.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ use crate::types::{
126126
PyAny, PyDict, PyEllipsis, PyModule, PyNone, PyNotImplemented, PyString, PyType,
127127
};
128128
use crate::version::PythonVersionInfo;
129-
use crate::{ffi, Bound, IntoPy, Py, PyNativeType, PyObject, PyTypeInfo};
129+
use crate::{ffi, Bound, IntoPy, Py, PyObject, PyTypeInfo};
130+
#[cfg(feature = "gil-refs")]
131+
use crate::PyNativeType;
130132
#[allow(deprecated)]
131133
use crate::{gil::GILPool, FromPyPointer};
132134
use std::ffi::{CStr, CString};
@@ -305,7 +307,7 @@ pub use nightly::Ungil;
305307
/// A marker token that represents holding the GIL.
306308
///
307309
/// It serves three main purposes:
308-
/// - It provides a global API for the Python interpreter, such as [`Python::eval`].
310+
/// - It provides a global API for the Python interpreter, such as [`Python::eval_bound`].
309311
/// - It can be passed to functions that require a proof of holding the GIL, such as
310312
/// [`Py::clone_ref`].
311313
/// - Its lifetime represents the scope of holding the GIL which can be used to create Rust
@@ -321,7 +323,7 @@ pub use nightly::Ungil;
321323
/// - In a function or method annotated with [`#[pyfunction]`](crate::pyfunction) or [`#[pymethods]`](crate::pymethods) you can declare it
322324
/// as a parameter, and PyO3 will pass in the token when Python code calls it.
323325
/// - If you already have something with a lifetime bound to the GIL, such as `&`[`PyAny`], you can
324-
/// use its [`.py()`][PyAny::py] method to get a token.
326+
/// use its `.py()` method to get a token.
325327
/// - When you need to acquire the GIL yourself, such as when calling Python code from Rust, you
326328
/// should call [`Python::with_gil`] to do that and pass your code as a closure to it.
327329
///
@@ -352,7 +354,7 @@ pub use nightly::Ungil;
352354
/// # Releasing and freeing memory
353355
///
354356
/// The [`Python`] type can be used to create references to variables owned by the Python
355-
/// interpreter, using functions such as [`Python::eval`] and `PyModule::import`. These
357+
/// interpreter, using functions such as `Python::eval` and `PyModule::import`. These
356358
/// references are tied to a [`GILPool`] whose references are not cleared until it is dropped.
357359
/// This can cause apparent "memory leaks" if it is kept around for a long time.
358360
///
@@ -552,13 +554,13 @@ impl<'py> Python<'py> {
552554
}
553555

554556
/// Deprecated version of [`Python::eval_bound`]
555-
#[cfg_attr(
556-
not(feature = "gil-refs"),
557+
#[cfg(feature = "gil-refs")]
558+
#[
557559
deprecated(
558560
since = "0.21.0",
559561
note = "`Python::eval` will be replaced by `Python::eval_bound` in a future PyO3 version"
560562
)
561-
)]
563+
]
562564
pub fn eval(
563565
self,
564566
code: &str,
@@ -601,13 +603,13 @@ impl<'py> Python<'py> {
601603
}
602604

603605
/// Deprecated version of [`Python::run_bound`]
604-
#[cfg_attr(
605-
not(feature = "gil-refs"),
606+
#[cfg(feature = "gil-refs")]
607+
#[
606608
deprecated(
607609
since = "0.21.0",
608610
note = "`Python::run` will be replaced by `Python::run_bound` in a future PyO3 version"
609611
)
610-
)]
612+
]
611613
pub fn run(
612614
self,
613615
code: &str,
@@ -728,13 +730,13 @@ impl<'py> Python<'py> {
728730
}
729731

730732
/// Gets the Python type object for type `T`.
731-
#[cfg_attr(
732-
not(feature = "gil-refs"),
733+
#[cfg(feature = "gil-refs")]
734+
#[
733735
deprecated(
734736
since = "0.21.0",
735737
note = "`Python::get_type` will be replaced by `Python::get_type_bound` in a future PyO3 version"
736738
)
737-
)]
739+
]
738740
#[inline]
739741
pub fn get_type<T>(self) -> &'py PyType
740742
where
@@ -753,13 +755,13 @@ impl<'py> Python<'py> {
753755
}
754756

755757
/// Deprecated form of [`Python::import_bound`]
756-
#[cfg_attr(
757-
not(feature = "gil-refs"),
758+
#[cfg(feature = "gil-refs")]
759+
#[
758760
deprecated(
759761
since = "0.21.0",
760762
note = "`Python::import` will be replaced by `Python::import_bound` in a future PyO3 version"
761763
)
762-
)]
764+
]
763765
pub fn import<N>(self, name: N) -> PyResult<&'py PyModule>
764766
where
765767
N: IntoPy<Py<PyString>>,

0 commit comments

Comments
 (0)