* Revamp PyType name functions to match PEP 737
PyType::name uses `tp_name`, which is not consistent.
[PEP 737](https://peps.python.org/pep-0737/) adds a new path forward,
so update PyType::name and add PyType::{module,fully_qualified_name}
to match the PEP.
* refactor conditional code to handle multiple Python versions better
* return `Bound<'py, str>`
* fixup
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
* Copy pasta implementation from types/string.rs
* changelog
* I think I don't need a special implementation for 3.10 or ABI
* Copy pasta tests
* Fix comment with correct type
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
* Fix implementation
* Use slice in tests
* Try renaming changelog file
* Fix doc example
* Fix doc example
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
---------
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
* use `ffi::MemberGef` for `#[pyo3(get)]` fields of `Py<T>`
* tidy up implementation
* make it work on MSRV :(
* fix docs and newsfragment
* clippy
* internal docs and coverage
* review: mejrs
* Improve the span and message for return types of pymethod/functions
* Don't pass the span
* fixup trybuild output
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
* Added `PyRef::as_super` and `PyRefMut::as_super` methods, including docstrings and tests. The implementation of these methods also required adding `#[repr(transparent)]` to the `PyRef` and `PyRefMut` structs.
* Added newsfragment entry.
* Changed the `AsRef<U>`/`AsMut<U>` impls for `PyRef` and `PyRefMut` to use the new `as_super` methods. Added the `PyRefMut::downgrade` associated function for converting `&PyRefMut` to `&PyRef`. Updated tests and docstrings to better demonstrate the new functionality.
* Fixed newsfragment filename.
* Removed unnecessary re-borrows flagged by clippy.
* retrigger checks
* Updated `PyRef::as_super`, `PyRefMut::as_super`, and `PyRefMut::downgrade` to use `.cast()` instead of `as _` pointer casts. Fixed typo.
* Updated `PyRef::as_super` and `PyRefMut::downgrade` to use `ptr_from_ref` for the initial cast to `*const _` instead of `as _` casts.
* Added `pyo3::internal_tricks::ptr_from_mut` function alongside the `ptr_from_ref` added in PR #4240. Updated `PyRefMut::as_super` to use this method instead of `as *mut _`.
* Updated the user guide to recommend `as_super` for accessing the base class instead of `as_ref`, and updated the subsequent example/doctest to demonstrate this functionality.
* Improved tests for the `as_super` methods.
* Updated newsfragment to include additional changes.
* Fixed formatting.
---------
Co-authored-by: jrudolph <jrudolph@anl.gov>
* Added `ToPyObject` and `Into<PyObject>` impls for `PyBackedStr`.
* Create 4205.added.md
* Added attributes limiting the `ToPyObject` and `IntoPy<PyObject>` impls to the case where `cfg(any(Py_3_10, not(Py_LIMITED_API)))`. When this cfg does not apply, the conversion is less trivial since the `storage` is actually `PyBytes`, not `PyString`.
* Fixed imports format.
* Updated the `ToPyObject` and `IntoPy<PyObject>` impls to support the `cfg(not(any(Py_3_10, not(Py_LIMITED_API))))` case by converting the `PyBytes` back to `PyString`.
* Added `ToPyObject` and `IntoPy<PyObject>` impls for `PyBackedBytes`.
* Added tests for the `PyBackedBytes` conversion impls.
* Updated newsfragment entry to include the `PyBackedBytes` impls.
* Changed the `IntoPy` and `ToPyObject` impls for `PyBackedBytes` to produce `PyBytes` regardless of the backing variant. Updated tests to demonstrate this.
* retrigger checks
* Updated `PyBackedStr` conversion tests to extract the result as a `PyBackedStr` instead of `&str` since the latter is not supported under some `cfg`'s.
* Fixed `IntoPy<PyObject> for PyBackedBytes` impl to create `bytes` for both storage types as intended. Updated test to properly catch the error.
---------
Co-authored-by: jrudolph <jrudolph@anl.gov>
* 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>
* Add feature controlling the global reference pool to enable avoiding its overhead.
* Document reference-pool feature in the performance guide.
* Invert semantics of feature to disable reference pool so the new behaviour becomes opt-in
* Remove delayed reference count increments as we cannot prevent reference count errors as long as these are available
* Adjust tests to be compatible with disable-reference-pool feature
* Adjust tests to be compatible with py-clone feature
* Adjust the GIL benchmark to the updated reference pool semantics.
* Further extend and clarify the documentation of the py-clone and disable-reference-pool features
* Replace disable-reference-pool feature by pyo3_disable_reference_pool conditional compilation flag
Such a flag is harder to use and thereby also harder to abuse. This seems
appropriate as this is purely a performance-oriented change which show only be
enabled by leaf crates and brings with it additional highly implicit sources of
process aborts.
* Add pyo3_leak_on_drop_without_reference_pool to turn aborts into leaks when the global reference pool is disabled and the GIL is not held
* Add `num-rational` support for Python's `fractions.Fraction` type
* Add newsfragment
* Use Bound instead
* Handle objs which atts are incorrect
* Add extra test
* Add tests for wasm32 arch
* add type for wasm32 clipppy