PyO3 v0.12.0 Release Notes
Release Date: 2020-09-12 // over 3 years ago-
➕ Added
- Add FFI definitions
Py_FinalizeEx
,PyOS_getsig
, andPyOS_setsig
. #1021 - ➕ Add
PyString::to_str
for accessingPyString
as&str
. #1023 - ➕ Add
Python::with_gil
for executing a closure with the Python GIL. #1037 - ➕ Add type information to failures in
PyAny::downcast()
. #1050 - Implement
Debug
forPyIterator
. #1051 - Add
PyBytes::new_with
andPyByteArray::new_with
for initialisingbytes
andbytearray
objects using a closure. #1074 - ➕ Add
#[derive(FromPyObject)]
macro for enums and structs. #1065 - Add
Py::as_ref
andPy::into_ref
for convertingPy<T>
to&T
. #1098 - ➕ Add ability to return
Result
types other thanPyResult
from#[pyfunction]
,#[pymethod]
and#[pyproto]
functions. #1106. - Implement
ToPyObject
,IntoPy
, andFromPyObject
for hashbrown'sHashMap
andHashSet
types (requires thehashbrown
feature). #1114 - Add
#[pyfunction(pass_module)]
and#[pyfn(pass_module)]
to pass the module object as the first function argument. #1143 - Add
PyModule::add_function
andPyModule::add_submodule
as typed alternatives toPyModule::add_wrapped
. #1143 - ➕ Add native
PyCFunction
andPyFunction
types. #1163
🔄 Changed
- 👻 Rework exception types: #1024 #1115
- Rename exception types from e.g.
RuntimeError
toPyRuntimeError
. The old names continue to exist but are deprecated. - Exception objects are now accessible as
&T
orPy<T>
, just like other Python-native types. - Rename
PyException::py_err()
toPyException::new_err()
. - Rename
PyUnicodeDecodeErr::new_err()
toPyUnicodeDecodeErr::new()
. - Remove
PyStopIteration::stop_iteration()
.
- Rename exception types from e.g.
- Require
T: Send
for the return valueT
ofPython::allow_threads
. #1036 - Rename
PYTHON_SYS_EXECUTABLE
toPYO3_PYTHON
. The old name will continue to work (undocumented) but will be removed in a future release. #1039 - Remove
unsafe
from signature ofPyType::as_type_ptr
. #1047 - 🔄 Change return type of
PyIterator::from_object
toPyResult<PyIterator>
(wasResult<PyIterator, PyDowncastError>
). #1051 IntoPy
is no longer implied byFromPy
. #1063- 🔄 Change
PyObject
to be a type alias forPy<PyAny>
. #1063 - Rework
PyErr
to be compatible with thestd::error::Error
trait: #1067 #1115- Implement
Display
,Error
,Send
andSync
forPyErr
andPyErrArguments
. - Add
PyErr::instance()
for accessingPyErr
as&PyBaseException
. PyErr
's fields are now an implementation detail. The equivalent values can be accessed withPyErr::ptype()
,PyErr::pvalue()
andPyErr::ptraceback()
.- Change receiver of
PyErr::print()
andPyErr::print_and_set_sys_last_vars()
to&self
(wasself
). - Remove
PyErrValue
,PyErr::from_value
,PyErr::into_normalized()
, andPyErr::normalize()
. - Remove
PyException::into()
. - Remove
Into<PyResult<T>>
forPyErr
andPyException
.
- Implement
- 🔄 Change methods generated by
#[pyproto]
to returnNotImplemented
if Python should try a reversed operation. #1072 - 🔄 Change argument to
PyModule::add
toimpl IntoPy<PyObject>
(wasimpl ToPyObject
). #1124
✂ Removed
- ✂ Remove many exception and
PyErr
APIs; see the "changed" section above. #1024 #1067 #1115 - Remove
PyString::to_string
(use newPyString::to_str
). #1023 - ✂ Remove
PyString::as_bytes
. #1023 - ✂ Remove
Python::register_any
. #1023 - Remove
GILGuard::acquire
from the public API. UsePython::acquire_gil
orPython::with_gil
. #1036 - ✂ Remove the
FromPy
trait. #1063 - ✂ Remove the
AsPyRef
trait. #1098
🛠 Fixed
- Correct FFI definitions
Py_SetProgramName
andPy_SetPythonHome
to take*const
arguments (was*mut
). #1021 - Fix
FromPyObject
fornum_bigint::BigInt
for Python objects with an__index__
method. #1027 - Correct FFI definition
_PyLong_AsByteArray
to take*mut c_uchar
argument (was*const c_uchar
). #1029 - 🛠 Fix segfault with
#[pyclass(dict, unsendable)]
. #1058 #1059 - 🛠 Fix using
&Self
as an argument type for functions in a#[pymethods]
block. #1071 - 🛠 Fix best-effort build against PyPy 3.6. #1092
- 🛠 Fix many cases of lifetime elision in
#[pyproto]
implementations. #1093 - 🛠 Fix detection of Python build configuration when cross-compiling. #1095
- Always link against libpython on android with the
extension-module
feature. #1095 - Fix the
+
operator not trying__radd__
when both__add__
and__radd__
are defined inPyNumberProtocol
(and similar for all other reversible operators). #1107 - 🛠 Fix building with Anaconda python. #1175
- Add FFI definitions