Skip to content

Commit

Permalink
reintroduce weakref constructors (#4491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Aug 25, 2024
1 parent c26bc3d commit 71b10b8
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 98 deletions.
24 changes: 12 additions & 12 deletions src/types/weakref/anyref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -147,7 +147,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -232,7 +232,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed()),
Expand Down Expand Up @@ -306,7 +306,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed()),
Expand Down Expand Up @@ -379,7 +379,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -455,7 +455,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -530,7 +530,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -600,7 +600,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let data = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&data)?;
/// let reference = PyWeakrefReference::new(&data)?;
///
/// assert_eq!(
/// parse_data(reference.as_borrowed())?,
Expand Down Expand Up @@ -672,7 +672,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let object = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&object)?;
/// let reference = PyWeakrefReference::new(&object)?;
///
/// assert_eq!(
/// get_class(reference.as_borrowed())?,
Expand Down Expand Up @@ -733,7 +733,7 @@ pub trait PyWeakrefMethods<'py> {
/// # fn main() -> PyResult<()> {
/// Python::with_gil(|py| {
/// let object = Bound::new(py, Foo{})?;
/// let reference = PyWeakrefReference::new_bound(&object)?;
/// let reference = PyWeakrefReference::new(&object)?;
///
/// assert_eq!(
/// get_class(reference.as_borrowed())?,
Expand Down Expand Up @@ -776,12 +776,12 @@ mod tests {
use crate::{Bound, PyResult, Python};

fn new_reference<'py>(object: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyWeakref>> {
let reference = PyWeakrefReference::new_bound(object)?;
let reference = PyWeakrefReference::new(object)?;
reference.into_any().downcast_into().map_err(Into::into)
}

fn new_proxy<'py>(object: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyWeakref>> {
let reference = PyWeakrefProxy::new_bound(object)?;
let reference = PyWeakrefProxy::new(object)?;
reference.into_any().downcast_into().map_err(Into::into)
}

Expand Down
Loading

0 comments on commit 71b10b8

Please sign in to comment.