Skip to content

Commit bdc372f

Browse files
authored
remove Deref implementations for old "gil refs" types (#4593)
* remove `Deref` implementations for old "gil refs" types * add changelog entries
1 parent 43ada7c commit bdc372f

File tree

5 files changed

+6
-18
lines changed

5 files changed

+6
-18
lines changed

newsfragments/4593.changed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use `DerefToPyAny` in blanket implementations of `From<Py<T>>` and `From<Bound<'py, T>>` for `PyObject`.

newsfragments/4593.removed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove implementations of `Deref` for `PyAny` and other "native" types.

src/exceptions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ macro_rules! create_exception_type_object {
274274
macro_rules! impl_native_exception (
275275
($name:ident, $exc_name:ident, $doc:expr, $layout:path $(, #checkfunction=$checkfunction:path)?) => (
276276
#[doc = $doc]
277+
#[repr(transparent)]
277278
#[allow(clippy::upper_case_acronyms)]
278279
pub struct $name($crate::PyAny);
279280

@@ -291,6 +292,7 @@ macro_rules! impl_windows_native_exception (
291292
($name:ident, $exc_name:ident, $doc:expr, $layout:path) => (
292293
#[cfg(windows)]
293294
#[doc = $doc]
295+
#[repr(transparent)]
294296
#[allow(clippy::upper_case_acronyms)]
295297
pub struct $name($crate::PyAny);
296298

src/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ unsafe impl<T> crate::AsPyPointer for Py<T> {
17981798

17991799
impl<T> std::convert::From<Py<T>> for PyObject
18001800
where
1801-
T: AsRef<PyAny>,
1801+
T: DerefToPyAny,
18021802
{
18031803
#[inline]
18041804
fn from(other: Py<T>) -> Self {
@@ -1808,7 +1808,7 @@ where
18081808

18091809
impl<T> std::convert::From<Bound<'_, T>> for PyObject
18101810
where
1811-
T: AsRef<PyAny>,
1811+
T: DerefToPyAny,
18121812
{
18131813
#[inline]
18141814
fn from(other: Bound<'_, T>) -> Self {

src/types/mod.rs

-16
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,6 @@ pub trait DerefToPyAny {
121121
#[macro_export]
122122
macro_rules! pyobject_native_type_named (
123123
($name:ty $(;$generics:ident)*) => {
124-
impl<$($generics,)*> ::std::convert::AsRef<$crate::PyAny> for $name {
125-
#[inline]
126-
fn as_ref(&self) -> &$crate::PyAny {
127-
&self.0
128-
}
129-
}
130-
131-
impl<$($generics,)*> ::std::ops::Deref for $name {
132-
type Target = $crate::PyAny;
133-
134-
#[inline]
135-
fn deref(&self) -> &$crate::PyAny {
136-
&self.0
137-
}
138-
}
139-
140124
impl $crate::types::DerefToPyAny for $name {}
141125
};
142126
);

0 commit comments

Comments
 (0)