This release introduces a substantial new direction for PyO3's API. The Bound<'py, T> smart pointer type has been added that replaces "GIL Refs" such as &'py PyAny and &'py PyList with smart-pointer forms Bound<'py, PyAny> and Bound<'py, PyList>. This new smart pointer brings ownership out of PyO3's internals and into user control. This has been done for sake of both performance and soundness.
The migration guide extensively details the intended transition to the new API. To allow users a more graceful upgrade path, PyO3 0.21 and 0.22 will maintain backwards compatibility support for the existing "GIL Refs" API.
As well as the Bound API, highlights of PyO3 0.21 include:
Support for compiling for GraalPy
Extended chrono / datetime conversions, including support for the abi3 feature and the chrono-tz crate
Simplifications to __next__ and __anext__ methods
PyO3 0.21 also includes two new experimental features:
experimental-async for a simple async fn integration between Rust and Python.
experimental-declarative-modules for a new simpler #[pymodule] syntax.
There have been numerous other smaller improvements, changes and fixes. For full details see the CHANGELOG.
Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:
FromPyObject, IntoPy<PyObject> and ToPyObject are implemented on std::duration::Duration#3670
Add PyString::to_cow. Add Py<PyString>::to_str, Py<PyString>::to_cow, and Py<PyString>::to_string_lossy, as ways to access Python string data safely beyond the GIL lifetime. #3677
Add Bound<T> and Borrowed<T> smart pointers as a new API for accessing Python objects. #3686
Add PyNativeType::as_borrowed to convert "GIL refs" to the new Bound smart pointer. #3692
Add FromPyObject::extract_bound method, to migrate FromPyObject implementations to the Bound API. #3706
Add gil-refs feature to allow continued use of the deprecated GIL Refs APIs. #3707
Add methods to PyAnyMethods for binary operators (add, sub, etc.) #3712
Add chrono-tz feature allowing conversion between chrono_tz::Tz and zoneinfo.ZoneInfo#3730
Add PyDictMethods::into_mapping, PyListMethods::into_sequence and PyTupleMethods::into_sequence. #3982
Changed
PyDict::from_sequence now takes a single argument of type &PyAny (previously took two arguments Python and PyObject). #3532
Deprecate Py::is_ellipsis and PyAny::is_ellipsis in favour of any.is(py.Ellipsis()). #3577
Split some PyTypeInfo functionality into new traits HasPyGilRef and PyTypeCheck. #3600
Deprecate PyTryFrom and PyTryInto traits in favor of any.downcast() via the PyTypeCheck and PyTypeInfo traits. #3601
Allow async methods to accept &self/&mut self#3609
FromPyObject for set types now also accept frozenset objects as input. #3632
FromPyObject for bool now also accepts NumPy's bool_ as input. #3638
Add AsRefSource associated type to PyNativeType. #3653
Rename .is_true to .is_truthy on PyAny and Py<PyAny> to clarify that the test is not based on identity with or equality to the True singleton. #3657
PyType::name is now PyType::qualname whereas PyType::name efficiently accesses the full name which includes the module name. #3660
The Iter(A)NextOutput types are now deprecated and __(a)next__ can directly return anything which can be converted into Python objects, i.e. awaitables do not need to be wrapped into IterANextOutput or Option any more. Option can still be used as well and returning None will trigger the fast path for __next__, stopping iteration without having to raise a StopIteration exception. #3661
Implement FromPyObject on chrono::DateTime<Tz> for all Tz, not just FixedOffset and Utc. #3663
Add lifetime parameter to PyTzInfoAccess trait. For the deprecated gil-ref API, the trait is now implemented for &'py PyTime and &'py PyDateTime instead of PyTime and PyDate. #3679
Calls to __traverse__ become no-ops for unsendable pyclasses if on the wrong thread, thereby avoiding hard aborts at the cost of potential leakage. #3689
Improve performance of extract::<i64> (and other integer types) by avoiding call to __index__() converting the value to an integer for 3.10+. Gives performance improvement of around 30% for successful extraction. #3742
Relax bound of FromPyObject for Py<T> to just T: PyTypeCheck. #3776
You can trigger a rebase of this PR by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Bumps pyo3 from 0.20.3 to 0.21.0.
Release notes
Sourced from pyo3's releases.
... (truncated)
Changelog
Sourced from pyo3's changelog.
... (truncated)
Commits
d854ea0
release: 0.21.09a38e70
Basic GraalPy Support (#3247)54ffaec
addAsRef
impls forPyBackedStr
andPyBackedBytes
(#3991)7d319a9
ci: tidy up benchmarks a little (#3986)aeb74c7
ci: use macos-14 runners (#3985)009cd32
Add into_mapping and into_sequence methods to Bound types (#3982)9808f71
ci: addupdate-ui-tests
nox session (#3979)20e477a
avoid reference count cycle in tuple extraction (#3976)990886e
docs: better documentFromPyObject
for&str
changes in migration guide (#...d0f5b6a
ci: updates for Rust 1.77 (#3978)You can trigger a rebase of this PR by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show