Skip to content

Commit 9fd849b

Browse files
authored
deprecate import_exception_bound (#5480)
* deprecate `import_exception_bound` * newsfragment
1 parent 63430bf commit 9fd849b

File tree

2 files changed

+8
-47
lines changed

2 files changed

+8
-47
lines changed

newsfragments/5480.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate `import_exception_bound` in favour of `import_exception`.

src/exceptions.rs

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ use std::ops;
1717
#[doc(hidden)]
1818
#[macro_export]
1919
macro_rules! impl_exception_boilerplate {
20-
($name: ident) => {
21-
$crate::impl_exception_boilerplate_bound!($name);
22-
23-
impl $crate::ToPyErr for $name {}
24-
};
25-
}
26-
27-
#[doc(hidden)]
28-
#[macro_export]
29-
macro_rules! impl_exception_boilerplate_bound {
3020
($name: ident) => {
3121
impl $name {
3222
/// Creates a new [`PyErr`] of this type.
@@ -41,6 +31,8 @@ macro_rules! impl_exception_boilerplate_bound {
4131
$crate::PyErr::new::<$name, A>(args)
4232
}
4333
}
34+
35+
impl $crate::ToPyErr for $name {}
4436
};
4537
}
4638

@@ -102,44 +94,12 @@ macro_rules! import_exception {
10294
};
10395
}
10496

105-
/// Variant of [`import_exception`](crate::import_exception) that does not emit code needed to
106-
/// use the imported exception type as a GIL Ref.
107-
///
108-
/// This is useful only during migration as a way to avoid generating needless code.
97+
/// Deprecated name for `import_exception!`.
10998
#[macro_export]
99+
#[deprecated(since = "0.27.0", note = "renamed to `import_exception!` instead")]
110100
macro_rules! import_exception_bound {
111101
($module: expr, $name: ident) => {
112-
/// A Rust type representing an exception defined in Python code.
113-
///
114-
/// This type was created by the [`pyo3::import_exception_bound!`] macro - see its documentation
115-
/// for more information.
116-
///
117-
/// [`pyo3::import_exception_bound!`]: https://docs.rs/pyo3/latest/pyo3/macro.import_exception.html "import_exception in pyo3"
118-
#[repr(transparent)]
119-
#[allow(non_camel_case_types)] // E.g. `socket.herror`
120-
pub struct $name($crate::PyAny);
121-
122-
$crate::impl_exception_boilerplate_bound!($name);
123-
124-
$crate::pyobject_native_type_info!(
125-
$name,
126-
$name::type_object_raw,
127-
::std::option::Option::Some(stringify!($module))
128-
);
129-
130-
impl $crate::types::DerefToPyAny for $name {}
131-
132-
impl $name {
133-
fn type_object_raw(py: $crate::Python<'_>) -> *mut $crate::ffi::PyTypeObject {
134-
use $crate::types::PyTypeMethods;
135-
static TYPE_OBJECT: $crate::impl_::exceptions::ImportedExceptionTypeObject =
136-
$crate::impl_::exceptions::ImportedExceptionTypeObject::new(
137-
stringify!($module),
138-
stringify!($name),
139-
);
140-
TYPE_OBJECT.get(py).as_type_ptr()
141-
}
142-
}
102+
$crate::import_exception!($module, $name);
143103
};
144104
}
145105

@@ -821,8 +781,8 @@ mod tests {
821781
use crate::types::{IntoPyDict, PyDict};
822782
use crate::PyErr;
823783

824-
import_exception_bound!(socket, gaierror);
825-
import_exception_bound!(email.errors, MessageError);
784+
import_exception!(socket, gaierror);
785+
import_exception!(email.errors, MessageError);
826786

827787
#[test]
828788
fn test_check_exception() {

0 commit comments

Comments
 (0)