Releases: PyO3/pyo3
PyO3 0.22.5
PyO3 0.22.4
This release is a security fix for PyO3 0.22.0 through 0.22.3.
The PyWeakrefMethods
trait functions for reading borrowed values from Python weak references have been identified as unsound, because they did not account for the possibility the last strong reference could be cleared at any time, leading the borrowed value to be dangling and risk of use-after-free.
PyO3 0.22.4 protects against this issue by making these methods permanently leak strong references. The methods are also marked deprecated and will be removed in PyO3 0.23. Users should switch to use the use PyWeakrefMethods
functions which return owned references (the deprecation messages indicate the appropriate upgrade paths).
These functions were added in PyO3 0.22.0; all versions from 0.22.0 through 0.22.3 have been yanked.
Aside from the security fix, PyO3 0.22.4 contains a number of other bugfixes, including:
- A fix for cases where
__traverse__
functions of base types were not called when using#[pyclass(extends = ...)]
- A fix for a regression in 0.22.3 where PyO3 generated code would trigger compile failures with crates using
#![forbid(unsafe_code)]
Thank you to the following contributors for the improvements:
PyO3 0.22.3
This release contains a number of quality improvements building upon PyO3 0.22.2.
Python function calls (using .call0()
, .call1(args)
and .call(args, kwargs)
) will now make use of the "vectorcall" calling conventions where possible, which can reduce overheads in many cases.
There have been several fix-ups to PyO3's FFI definitions. A new pyo3::ffi::compat
namespace has been added which offers some backwards-compatible implementations of Python APIs otherwise normally only available on recent Pythons.
There have been numerous other bug-fixes and minor tweaks to improve user experience.
Thank you to the following contributors for the improvements:
@birkenfeld
@ChayimFriedman2
@csernazs
@davidhewitt
@Icxolu
@jakelishman
@LilyFoote
@ngoldbaum
@Zyell
PyO3 0.22.2
This release contains some minor reliability fixes building upon PyO3 0.22.1.
As PyO3 is still working on supporting freethreaded Python (upcoming in 3.13), support has been gated behind an UNSAFE_PYO3_BUILD_FREE_THREADED=1
environment variable to avoid unsuspecting users running into broken builds.
Packages built for the abi3
stable ABI will now use FFI functions for refcounting instead of inline reference count modifications on all versions of the stable ABI (previously only abi3
builds for 3.12 and up would use FFI functions). This helps mitigate interactions of old versions of the stable ABI with future CPython releases which do more complex reference counting (e.g. immortal objects, freethreaded reference counting).
The #[pymodule]
declarative module now supports directly receiving options. (E.g. #[pymodule(name = "foo")]
, which would previously have been written as two attributes #[pymodule] #[pyo3(name = "foo")]
.)
A compile error on Rust 1.78 related to use of c""
literals has been fixed.
Thank you to the following contributors for the improvements:
@davidhewitt
@FlickerSoul
@gi0baro
@Icxolu
@MatthijsKok
@styvane
PyO3 0.22.1
This patch release improves some cases related to new functionality in PyO3 0.22.
PartialEq<bool>
has been added for Bound<'py, PyBool>
.
The #[pyo3(submodule)]
attribute has been added for declarative modules to stop submodules from generating an external C symbol for importing the submodule directly (which is typically never used). Declarative modules will also now correctly add items annotated with full-path attributes like #[pyo3::prelude::pyfunction]
.
The #[pyclass(eq)]
option will no longer raise a TypeError
on comparison against types not in the signature.
A #[setter]
in #[pymethods]
with an Option<T>
input will no longer raise a deprecation warning.
A regression has been fixed in conversions for 128-bit integers on big-endian platforms.
Thank you to the following contributors for the improvements:
@alex
@davidhewitt
@jatoben
@kylebarron
@musicinmybrain
@ngoldbaum
@Owen-CH-Leung
PyO3 0.22.0
This release introduces support for Python 3.13. Please note that Python 3.13 is still in beta, and while breaking changes are not expected it is very possible that code compiled against Python 3.13 beta versions will be incompatible with the final 3.13 release later in the year.
The minimum supported Rust version has been increased to Rust 1.63.
PyO3's deferred reference counting used to implement Clone for Py<T>
without the global interpreter lock has been demonstrated to be impossible to implement safely in the general case and has consequently been changed to panic instead of deferring when cloning Py<T>
without the GIL being held. Given the nature of panics inside Clone
operations being a potential footgun, this implementation has been moved behind the opt-in py-clone
feature.
Other particularly notable changes include:
- The
#[pyclass]
macro now has additional options#[pyclass(eq, ord, hash)]
to automatically generate Python implementations for equality, ordering and hashing based upon the RustPartialEq
,PartialOrd
andHash
traits. This can ensure consistency and reduce boilerplate compared to implementing__eq__
,__hash__
and so on manually. - The
experimental-declarative-modules
feature to support#[pymodule]
on Rustmod
items has been stabilised (and the feature flag removed). The existing implementation of#[pymodule]
onfn
items is still present but soft-deprecated; in the future new features will likely be added only to declarative modules, and thefn
modules may eventually be deprecated and removed. - The GIL Refs API deprecation started in PyO3 0.21 continues with all related APIs now being gated behind the
gil-refs
feature, and unconditionally deprecated. In PyO3 0.23 these APIs are expected to be removed.
There have been numerous other smaller improvements, changes and fixes. For full details see the CHANGELOG.
Please consult the migration guide for help upgrading.
Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following contributors' commits are included in this release:
@adamreichold
@alex
@aneeshusa
@birkenfeld
@blmarket
@Cheukting
@cmpute
@codeguru42
@Databean
@davidbrochart
@davidhewitt
@deedy5
@dmatos2012
@Icxolu
@JRRudy1
@lfn3
@liammcinroy
@linhr
@mejrs
@messense
@newcomertv
@reswqa
@sk1p
@SuperJappie08
@Tpt
@wyfo
@xen0n
@Zyell
PyO3 0.21.2
This release contains some fixes to compile-time edge cases for the PyO3 0.21 series:
- A missing deprecation warning for the GIL Ref constructor
PySet::empty
has now been added. #[pymodule]
functions will no longer triggermissing_docs
lints on their generated code.- Incorrect implementations of
__traverse__
in#[pymethods]
will now emit a better error. - Extension modules on AIX will now link to
libpython
.
This release also fixes some compile errors for the experimental-async
and experimental-declarative-modules
features, and corrects some documentation typos.
Thank you to the following users for the improvements:
@adamreichold
@blmarket
@davidhewitt
@Icxolu
@lfn3
@messense
@wyfo
PyO3 0.21.1
This release is a set of touch-ups to PyO3 0.21 to fix cases found as adoption of PyO3 0.21.0 progressed.
The new PyBackedStr
and PyBackedBytes
types have had a large range of standard traits implemented, including Clone
, PartialEq
, Hash
, PartialOrd
, Display
, Debug
, Send
and Sync
.
The argument to a #[setter]
function now accepts the full range of input types as any other function argument in a #[pymethods]
block, and will now correctly handle a #[pyo3(from_py_with = "...")]
annotation.
Some procedural macro output has been adjusted to reuse more code and make it easier to reach complete code coverage in projects using PyO3. The import_exception_bound!
macro has been added to further assist with coverage during migration, by skipping generating code which is only needed to use the exception as a GIL Ref.
Finally, the experimental-async
feature now correctly handles async fn
in #[pymethods]
which have a &self
or &mut self
receiver plus additional arguments.
Thank you to the following users for the improvements:
@alex
@davidhewitt
@geo7
@Icxolu
@reswqa
@rikushoney
@tisonkun
PyO3 0.21.0
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 theabi3
feature and thechrono-tz
crate - Simplifications to
__next__
and__anext__
methods
PyO3 0.21 also includes two new experimental features:
experimental-async
for a simpleasync 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.
Please consult the migration guide for help upgrading.
Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:
@acceptacross
@adamreichold
@aldanor
@alex
@alonme
@alxhill
@birkenfeld
@btel
@daemontus
@davidhewitt
@dmatos2012
@Hamatti
@Icxolu
@jadedpasta
@Jerry-Master
@jessekrubin
@Jgfrausing
@juntyr
@kushaldas
@LilyFoote
@maffoo
@mejrs
@messense
@mkovaxx
@neachdainn
@orhun
@samuelcolvin
@snuderl
@suriya-ganesh
@timfel
@Tpt
@wyfo
@Xuanwo
PyO3 0.21.0-beta.0
This release is a prerelease of PyO3 0.21 specifically aimed at confirming the new "Bound" API delivers the expected payoffs to downstream projects and that the migration pathway is manageable.
Some documentation is not yet completely polished, and there are some deprecation warnings which are due to be added. The expectation is that this work will take a week or two at most, and the final 0.21 release will follow at that point.
To read about the new Bound API, best to start with the migration guide entry.
If you test out the new API and have feedback, please open a new GitHub issue or discussion, or reach out on PyO3's new Discord. Feedback in this time period before the final release is particularly appreciated.
A more detailed release announcement and acknowledgements will be written with the final release.