Skip to content

Commit

Permalink
Add weakref Python types (#3835)
Browse files Browse the repository at this point in the history
* Add vscode folder to gitignore

* Initial work on PyWeakRef (weakref.ReferenceType)

* Add documentation for PyWeakRef::upgrade

* Add missing docs for PyWeakRef

* Add PyWeakProxy

* Add PyWeakCallableProxy

* Add PyWeakRefMethods::upgrade_exact and prevent unnecessary panicing

* Change PyWeakRefMethods to exclude infeasible errors.

As a result of the checks  made about the objectpointers in PyO3, all
 errors in PyWeakref_GetObject are already caught. Therefor there is no
 need to check for these errors in the non-ffi layer.

* Add towncrier changes

* Update weakref type doctests to use `py.run_bound`

* Fix to adhere to MSRV

* Make weakref tests independent from macros feature

* Change Weakref tests

* Remove forgotten Debug marcos

* Processed .gitignore and PyResultExt feedback

* Change new methods of weakref types to remove dangling pointers

* Change to reflect deprecation of PyErr::value for PyErr::value_bound

* Change Tests so different class name in older python versions is accounted for

* Change formatting

* Make tests ABI3 compatible

* Prevent the use of PyClass in test for weakref under abi3 Python 3.7 and 3.8

* Disable weakref types when targeting PyPy

* Remove needless borrow from CallableProxy test

* Add Borrowed variants of upgrade and upgrade exact to trait

* Added tests for weakref borrow_upgrade methods

* Change PyWeakRefMethods method names to be more consistent

* Change weakref constructors to take PyAny for main target

* Add track_caller to all panicing weakref methods

* Add PyWeakRefMethods::upgrade*_as_unchecked

* Fix PyWeakProxy and PyWeakCallableProxy Documentation

* Replace deprecated wrap_pyfunction with bound equivalent

* Add (Generic) PyWeakref Type

* Reworked Proxy types into one (PyWeakrefProxy)

* Rename PyWeakRef to PyWeakrefReference

* Change PyWeakrefReference to only use type pointer when it exists

* Remove `#[track_caller]` annotations for now

* Make the gil-refs function feature dependent

* Remove unused AsPyPointer import

* Change docs links to PyNone to not include private module

* Fix string based examples

* Change tests to work for Python 3.13

* Fix cargo clippy for Python 3.13

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
  • Loading branch information
SuperJappie08 and davidhewitt authored May 31, 2024
1 parent d1a7cf4 commit 25c1db4
Show file tree
Hide file tree
Showing 7 changed files with 4,570 additions and 0 deletions.
1 change: 1 addition & 0 deletions newsfragments/3835.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `PyWeakref`, `PyWeakrefReference` and `PyWeakrefProxy`.
1 change: 1 addition & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ pub use crate::types::string::PyStringMethods;
pub use crate::types::traceback::PyTracebackMethods;
pub use crate::types::tuple::PyTupleMethods;
pub use crate::types::typeobject::PyTypeMethods;
pub use crate::types::weakref::PyWeakrefMethods;
2 changes: 2 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub use self::string::{PyString, PyString as PyUnicode, PyStringMethods};
pub use self::traceback::{PyTraceback, PyTracebackMethods};
pub use self::tuple::{PyTuple, PyTupleMethods};
pub use self::typeobject::{PyType, PyTypeMethods};
pub use self::weakref::{PyWeakref, PyWeakrefMethods, PyWeakrefProxy, PyWeakrefReference};

/// Iteration over Python collections.
///
Expand Down Expand Up @@ -365,3 +366,4 @@ pub(crate) mod string;
pub(crate) mod traceback;
pub(crate) mod tuple;
pub(crate) mod typeobject;
pub(crate) mod weakref;
Loading

0 comments on commit 25c1db4

Please sign in to comment.