PyO3: Python解释器的Rust绑定
PyO3: Python解释器的Rust绑定This release is a set of quality-of-life improvements and bugfixes for PyO3 0.13.0. All new functionality adds flexibility to pyo3 in rarer cases, such as fixing #[pyclass(dict)]
support for the abi3
feature (on compatible Python versions). In addition, a long-overdue initiative to reconcile PyO3's ffi
definitions with the current state of the upstream Python API has started. This resulted in a number of new deprecations where mismatches were found.
For full details of all changes, see the CHANGELOG.
Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:
@cecini
@dalcde
@daniil-konovalenko
@davidhewitt
@kngwyu
@konstin
@nw0
@OrangeTux
Assets
2
The major feature for this PyO3 release is support for the CPython limited API. This is an opt-in feature when building extension modules which makes it possible for the built wheel to be installable on multiple Python versions.
As well as this, a number of other refinements, fixes, and performance improvements have been merged into this release. In particular, note that the internal "macros" crates have been renamed to pyo3-macros
and pyo3-macros-backend
for clarity and consistency (previously pyo3cls
and pyo3-derive-backend
).
For full details of all changes, see the CHANGELOG.
Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:
@AleksaC
@alex
@Askaholic
@aviramha
@birkenfeld
@Daggy1234
@davidhewitt
@dvermd
@kngwyu
@konstin
@Palladinium
@roblabla
@scalexm
@Stranger6667
Assets
2
This release fixes a reference count issue discovered in PyO3 0.12.3
, present in the implementation of From<Py<T>>
for PyObject
. Usage of this implementation would lead to an incorrect Python reference count decrease, likely leading to use-after-free.
This regression was only present in the PyO3 0.12
series. The offending implementation was used only in one location inside the PyO3 codebase itself, though of course is likely used in downstream code. As a result, previous PyO3 versions in the 0.12
series will be yanked.
Sincerest apologies for the inconvenience.
Fixed
- Fix reference count bug in implementation of
From<Py<T>>
forPyObject
, a regression introduced in PyO3 0.12. #1297
Assets
2
This release fixes support for Rust versions 1.39 through Rust 1.44, which was erroneously broken in PyO3 0.12.2. Thanks to @mtreinish for the quick bug report!
Assets
2
This release adds the ability to specify keyword-only arguments in #[pyfunction]
definitions, a new function Python::check_signals
, and a couple of smaller refinements improving upon PyO3 0.12.1.
Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:
Assets
2
This release contains a couple of bugfixes to resolve complation issues with 0.12.0 on specific targets. Thank you to @alex and @mtreinish for the bug reports and subsequent patches.
Fixed
Assets
2
This release includes a few careful revisions to the PyO3 API with the intention to make it easier to learn and use. The PyErr
type is reworked to implement std::error::Error
. The FromPy
trait is removed. Finally, the PyObject
struct is now just a type alias to Py<PyAny>
. While we do not take pleasure in making breaking changes for users' code, we have done so with careful thought to make migration as simple as possible while also allowing the PyO3 API to mature. Please see the migration guide for help upgrading if any of these changes affect you.
Also added is a new #[derive(FromPyObject)]
macro, which enables a convenient way to accept arguments of the Python "type" Union
. (See the guide entry on this new feature.)
There have been many other improvements and bugfixes too numerous to go into detail here. For the full list, see the CHANGELOG.
Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback on the way to PyO3 0.12. The full list of users who commited at least one contribution to PyO3 0.12 is below:
@alex
@birkenfeld
@cathay4t
@davidhewitt
@Hakuyume
@Hywan
@kngwyu
@konstin
@marioortizmanero
@MoritzLangenstein
@mtreinish
@mvaled
@nagisa
@noam93k
@Progdrasil
@programmerjake
@rob-thatcher
@sebpuetz
@vorner
@vthriller
Assets
2
This is our first version that supports the stable Rust toolchain. The minimum required version is 1.39.0.
Thank you @davidhewitt @scalexm @tamuhey @konstin @Nateckert @Alexander-N @m-ou-se and all issue reporters
Maybe the most influential change is now #[pyclass]
requires Send
. Please see the migration guide for more.
Added
- Support stable versions of Rust (>=1.39). #969
- Add FFI definition
PyObject_AsFileDescriptor
. #938 - Add
PyByteArray::data
,PyByteArray::as_bytes
, andPyByteArray::as_bytes_mut
. #967 - Add
GILOnceCell
to use in situations wherelazy_static
oronce_cell
can deadlock. #975 - Add
Py::borrow
,Py::borrow_mut
,Py::try_borrow
, andPy::try_borrow_mut
for accessing#[pyclass]
values. #976 - Add
IterNextOutput
andIterANextOutput
for returning from__next__
/__anext__
. #997
Changed
- Simplify internals of
#[pyo3(get)]
attribute. (Remove the hidden APIGetPropertyValue
.) #934 - Call
Py_Finalize
at exit to flush buffers, etc. #943 - Add type parameter to PyBuffer. #951
- Require
Send
bound for#[pyclass]
. #966 - Add
Python
argument to most methods onPyObject
andPy<T>
to ensure GIL safety. #970 - Change signature of
PyTypeObject::type_object()
- now takesPython
argument and returns&PyType
. #970 - Change return type of
PyTuple::slice()
andPyTuple::split_from()
fromPy<PyTuple>
to&PyTuple
. #970 - Change return type of
PyTuple::as_slice
to&[&PyAny]
. #971 - Rename
PyTypeInfo::type_object
totype_object_raw
, and addPython
argument. #975 - Update
num-complex
optional dependendency from0.2
to0.3
. #977 - Update
num-bigint
optional dependendency from0.2
to0.3
. #978 #[pyproto]
is re-implemented without specialization. #961PyClassAlloc::alloc
is renamed toPyClassAlloc::new
. #990#[pyproto]
methods can now have return valueT
orPyResult<T>
(previously onlyPyResult<T>
was supported). #996#[pyproto]
methods can now skip annotating the return type if it is()
. #998
Removed
- Remove
ManagedPyRef
(unused, and needs specialization) #930
Fixed
- Fix passing explicit
None
toOption<T>
argument#[pyfunction]
with a default value. #936 - Fix
PyClass.__new__
's not respecting subclasses when inherited by a Python class. #990 - Fix returning
Option<T>
from#[pyproto]
methods. #996 - Fix accepting
PyRef<Self>
andPyRefMut<Self>
to#[getter]
and#[setter]
methods. #999
Assets
2
0.10.0 has a deadlock bug and was yanked. Thank you @davidhewitt for fixing it!
Fixed
- Fix deadlock in
Python::acquire_gil()
after dropping aPyObject
orPy<T>
. #924
Assets
2
Assets
2
PyO3 0.9.0 Alpha.1
There are some breaking changes...
But I believe in most cases, you just change this
impl MyClass {
#[new]
fn new(init: &PyRawObject) {
init.init(MyClass {});
}
}
to
impl MyClass {
#[new]
fn new() -> Self {
MyClass {}
}
}
and everything works fine.
Please read the guide for detail.
CHANGELOG
Changed
- The blanket implementations for
FromPyObject
for&T
and&mut T
are no longer specializable. ImplementPyTryFrom
for your type to control the behavior ofFromPyObject::extract()
for your types. - The implementation for
IntoPy<U> for T
whereU: FromPy<T>
is no longer specializable. Control the behavior of this via the implementation ofFromPy
. #[new]
does not takePyRawObject
and can reutrnSelf
#683- Use
parking_lot::Mutex
instead ofspin::Mutex
#734
Added
- Implemented
IntoIterator
forPySet
andPyFrozenSet
. #716 PyClass
,PyClassShell
,PyObjectLayout
,PyClassInitializer
#683
Fixed
- Clear error indicator when the exception is handled on the Rust side. #719
- Fixed unsoundness of subclassing. #683.
Removed
PyRef
,PyRefMut
,PyRawObject
#683
Assets
2
Added
- Support for #[name = "foo"] attribute for #[pyfunction] and in #[pymethods]. #692
- Implemented FromPyObject for HashMap and BTreeMap
Assets
2
Added
- FFI compatibility for PEP 590 Vectorcall. #641
Fixed
- Fix PySequenceProtocol::set_item. #624
- Fix a corner case of BigInt::FromPyObject. #630
- Fix index errors in parameter conversion. #631
- Fix handling of invalid utf-8 sequences in
PyString::as_bytes
. #639
andPyString::to_string_lossy
#642. - Remove
__contains__
and__iter__
from PyMappingProtocol. #644 - Fix proc-macro definition of PySetAttrProtocol. #645
Assets
2
NOTE Please take care that PyO3 <= 0.8.0 doesn't support the latest nightly (See #614 for detail).
Added
- Conversion between num-bigint and Python int. #608
Fixed
Assets
2
konstin released this
Added
module
argument topyclass
macro. #499py_run!
macro #512- Use existing fields and methods before calling custom getattr. #505
PyBytes
can now be indexed just likeVec<u8>
- Implement
IntoPy<PyObject>
forPyRef
andPyRefMut
.
Removed
IntoPyObject
was replaced withIntoPy<PyObject>
#[pyclass(subclass)]
is hidden aunsound-subclass
feature because it's causing segmentation faults.
Fixed
- More readable error message for generics in pyclass #503
Changed
- Implementing the Using the
gc
parameter forpyclass
(e.g.#[pyclass(gc)]
) without implementing theclass::PyGCProtocol
trait is now a compile-time error. Failing to implement this trait could lead to segfaults. #532 PyByteArray::data
has been replaced withPyDataArray::to_vec
because returning a&[u8]
is unsound. (See this comment for a great write-up for why that was unsound)- Replace
mashup
withpaste
. GILPool
gained aPython
marker to prevent it from being misused to release Python objects without the GIL held.
Assets
2
Added
- PyPy support by omerbenamram in #393
- Have
PyModule
generate an index of its members (__all__
list). - Allow
slf: PyRef<T>
for pyclass(#419) - Allow to use lifetime specifiers in
pymethods
- Add
marshal
module. #460
Changed
Python::run
returnsPyResult<()>
instead ofPyResult<&PyAny>
.- Methods decorated with
#[getter]
and#[setter]
can now omit wrapping the
result type inPyResult
if they don't raise exceptions.
Fixed
type_object::PyTypeObject
has been marked unsafe because breaking the contracttype_object::PyTypeObject::init_type
can lead to UB.- Fixed automatic derive of
PySequenceProtocol
implementation in #423. - Capitalization & better wording to README.md.
- Docstrings of properties is now properly set using the doc of the
#[getter]
method. - Fixed issues with
pymethods
crashing on doc comments containing double quotes. PySet::new
andPyFrozenSet::new
now returnPyResult<&Py[Frozen]Set>
; exceptions are raised if
the items are not hashable.- Fixed building using
venv
on Windows. PyTuple::new
now returns&PyTuple
instead ofPy<PyTuple>
.
Assets
2
Regressions
- Currently, #341 causes
cargo test
to fail with weird linking errors when theextension-module
feature is activated. For now you can work around this by making theextension-module
feature optional and running the tests withcargo test --no-default-features
:
[dependencies.pyo3]
version = "0.6.0"
[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
Added
- Added a
wrap_pymodule!
macro similar to the existingwrap_pyfunction!
macro. Only available on python 3 - Added support for cross compiling (e.g. to arm v7) by mtp401 in #327. See the "Cross Compiling" section in the "Building and Distribution" chapter of the guide for more details.
- The
PyRef
andPyRefMut
types, which allow to differentiate between an instance of a rust struct on the rust heap and an instance that is embedded inside a python object. By kngwyu in #335 - Added
FromPy<T>
andIntoPy<T>
which are equivalent toFrom<T>
andInto<T>
except that they require a gil token. - Added
ManagedPyRef
, which should eventually replaceToBorrowedObject
.
Changed
- Renamed
PyObjectRef
toPyAny
in #388 - Renamed
add_function
toadd_wrapped
as it now also supports modules. - Renamed
#[pymodinit]
to#[pymodule]
py.init(|| value)
becomesPy::new(value)
py.init_ref(|| value)
becomesPyRef::new(value)
py.init_mut(|| value)
becomesPyRefMut::new(value)
.PyRawObject::init
is now infallible, e.g. it returns()
instead ofPyResult<()>
.- Renamed
py_exception!
tocreate_exception!
and refactored the error macros. - Renamed
wrap_function!
towrap_pyfunction!
- Renamed
#[prop(get, set)]
to#[pyo3(get, set)]
#[pyfunction]
now supports the same arguments as#[pyfn()]
- Some macros now emit proper spanned errors instead of panics.
- Migrated to the 2018 edition
crate::types::exceptions
moved tocrate::exceptions
- Replace
IntoPyTuple
withIntoPy<Py<PyTuple>>
. IntoPyPointer
andToPyPointer
moved into the crate root.class::CompareOp
moved intoclass::basic::CompareOp
- PyTypeObject is now a direct subtrait PyTypeCreate, removing the old cyclical implementation in #350
- Add
PyList::{sort, reverse}
by chr1sj0nes in #357 and #358 - Renamed the
typeob
module totype_object
Removed
PyToken
was removed due to unsoundness (See #94).- Removed the unnecessary type parameter from
PyObjectAlloc
NoArgs
. Just use an empty tuplePyObjectWithGIL
.PyNativeType
is sufficient now that PyToken is removed.
Fixed
Assets
2
konstin released this
Assets
2
Fixed
- Fix memory leak in ArrayList by kngwyu #316
konstin released this
Assets
2
Fixed
- Fix undeterministic segfaults when creating many objects by kngwyu in #281
konstin released this
Assets
2
Added
#[pyclass]
objects can now be returned from rust functionsPyComplex
by kngwyu in #226PyDict::from_sequence()
, equivalent todict([(key, val), ...])
- Bindings for the
datetime
standard library types:PyDate
,PyTime
,PyDateTime
,PyTzInfo
,PyDelta
with associatedffi
types, by pganssle #200. PyString
,PyUnicode
, andPyBytes
now have anas_bytes()
method that returns&[u8]
.PyObjectProtocol::get_type_ptr()
by ijl in #242
Removed
- Removed most entries from the prelude. The new prelude is small and clear.
- Slowly removing specialization uses
PyString
,PyUnicode
, andPyBytes
no longer have adata()
method
(replaced byas_bytes()
) andPyStringData
has been removed.
Changed
- Removes the types from the root module and the prelude. They now live in
pyo3::types
instead. - All exceptions are consturcted with
py_err
instead ofnew
, as they returnPyErr
and notSelf
. as_mut
and friends take and&mut self
instead of&self
ObjectProtocol::call
now takes anOption<&PyDict>
for the kwargs instead of anIntoPyDictPointer
.IntoPyDictPointer
was replace byIntoPyDict
which doesn't convertPyDict
itself anymore and returns aPyDict
instead of*mut PyObject
.PyTuple::new
now takes anIntoIterator
instead of a slice- Updated to syn 0.15
- Splitted
PyTypeObject
intoPyTypeObject
without the create method andPyTypeCreate
with requiresPyObjectAlloc<Self> + PyTypeInfo + Sized
. - Ran
cargo edition --fix
which prefixed path withcrate::
for rust 2018 - Renamed
async
topyasync
as async will be a keyword in the 2018 edition. - Starting to use
NonNull<*mut PyObject>
for Py and PyObject by ijl #260
Fixed
- Added an explanation that the GIL can temporarily be released even while holding a GILGuard.
- Lots of clippy errors
- Fix segfault on calling an unknown method on a PyObject
- Work around a bug in the rust compiler by kngwyu #252
- Fixed a segfault with subclassing pyo3 create classes and using
__class__
by kngwyu #263
Removed
- The pyobject_extract macro
PyO3 0.4.0
konstin released this
Removed
- Conversions from tuples to PyDict due to rust-lang/rust#52050
Changed
- Merged both examples into one
- Rustfmt all the things
✔️ - Switched to Keep a Changelog
PyO3 0.3.2
konstin released this
Changes
- Replaced
concat_idents
with mashup
PyO3 0.3.1
konstin released this
Changes
- Fixed scoping bug in pyobject_native_type that would break rust-numpy
PyO3 v0.2.7
konstin released this
0.2.7 backports the compilation fix with current nightlies, so pyo3 stays usable until 0.3 is released.
PyO3 0.2.6
fafhrd91 released this
Changes
- Fix compatibility with TryFrom trait
PyO3 0.2.5
fafhrd91 released this
PyO3 0.2.4
fafhrd91 released this
Watchers:61 |
Star:4005 |
Fork:260 |
创建时间: 2017-05-13 13:22:06 |
最后Commits: 3天前 |
190eb72
Compare
This release contains small improvements over PyO3 0.13.1. The minimum supported Rust version has been lowered to Rust 1.41. A
serde
feature has been added which provides implementations ofSerialize
andDeserialize
for types inside thePy<T>
smart pointer.Of note is that this release disables automatic finalization of the Python interpreter at program exit for Rust binaries embedding the Python interpreter. This was found to cause a number of issues with C extensions such as Tensorflow and Scipy which were sensitive to the deinitialization order. For the vast majority of users this should cause no impact or fix a number of problem cases. For the minority who did depend on finalization, the unsafe method
with_embedded_python_interpreter
has been added to manually control the interpreter lifecycle.For full details of all changes, see the CHANGELOG.
Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:
@alex
@awestlake87
@birkenfeld
@cfbolz
@daniil-konovalenko
@davidhewitt
@decathorpe
@ijl
@kangalioo
@kngwyu
@lazka
@nw0
@tdamsma