From 7e4d1c41e3eebe757931f45e0bf2b3032cdc5eb1 Mon Sep 17 00:00:00 2001 From: Yuji Kanagawa Date: Wed, 13 May 2020 13:24:36 +0900 Subject: [PATCH] Bump version to 0.10.0 (#919) * Bump version to 0.10.0 * Apply suggestions from code review Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com> * Improve CHANGELOG completeness and messaging * ObjectProtocol was in prelude Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com> --- CHANGELOG.md | 59 ++++++++++++++++++---------------- Cargo.toml | 4 +-- README.md | 4 +-- guide/src/get_started.md | 4 +-- guide/src/migration.md | 45 ++++++++++++++++++++++---- pyo3-derive-backend/Cargo.toml | 2 +- pyo3cls/Cargo.toml | 4 +-- src/lib.rs | 4 +-- 8 files changed, 82 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc00ad44..de82f92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,39 +5,43 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.10.0] ### Added -- `_PyDict_NewPresized`. [#849](https://github.com/PyO3/pyo3/pull/849) -- `IntoPy` for `HashSet` and `BTreeSet`. [#864](https://github.com/PyO3/pyo3/pull/864) -- `PyAny::dir`. [#886](https://github.com/PyO3/pyo3/pull/886) -- `impl Clone` for `PyObject` and `Py`. [#908](https://github.com/PyO3/pyo3/pull/908) -- All builtin types (`PyList`, `PyTuple`, `PyDict`) etc. now implement `Deref`. [#911](https://github.com/PyO3/pyo3/pull/911) -- `PyCell` now implements `Deref`. [#911](https://github.com/PyO3/pyo3/pull/911) -- Methods and associated constants can now be annotated with `#[classattr]` to define class attributes. [#905](https://github.com/PyO3/pyo3/pull/905) [#914](https://github.com/PyO3/pyo3/pull/914) +- Add FFI definition `_PyDict_NewPresized`. [#849](https://github.com/PyO3/pyo3/pull/849) +- Implement `IntoPy` for `HashSet` and `BTreeSet`. [#864](https://github.com/PyO3/pyo3/pull/864) +- Add `PyAny::dir` method. [#886](https://github.com/PyO3/pyo3/pull/886) +- Gate macros behind a `macros` feature (enabled by default). [#897](https://github.com/PyO3/pyo3/pull/897) +- Add ability to define class attributes using `#[classattr]` on functions in `#[pymethods]`. [#905](https://github.com/PyO3/pyo3/pull/905) +- Implement `Clone` for `PyObject` and `Py`. [#908](https://github.com/PyO3/pyo3/pull/908) +- Implement `Deref` for all builtin types. (`PyList`, `PyTuple`, `PyDict` etc.) [#911](https://github.com/PyO3/pyo3/pull/911) +- Implement `Deref` for `PyCell`. [#911](https://github.com/PyO3/pyo3/pull/911) +- Add `#[classattr]` support for associated constants in `#[pymethods]`. [#914](https://github.com/PyO3/pyo3/pull/914) ### Changed -- Panics from Rust will now be caught and raised as Python errors. [#797](https://github.com/PyO3/pyo3/pull/797) -- `PyObject` and `Py` reference counts are now decremented sooner after `drop()`. [#851](https://github.com/PyO3/pyo3/pull/851) - - When the GIL is held, the refcount is now decreased immediately on drop. (Previously would wait until just before releasing the GIL.) - - When the GIL is not held, the refcount is now decreased when the GIL is next acquired. (Previously would wait until next time the GIL was released.) -- `FromPyObject` for `Py` now works for a wider range of `T`, in particular for `T: PyClass`. [#880](https://github.com/PyO3/pyo3/pull/880) -- Some functions such as `PyList::get_item` which return borrowed objects at the C ffi layer now return owned objects at the PyO3 layer, for safety reasons. [#890](https://github.com/PyO3/pyo3/pull/890) -- The `GILGuard` returned from `Python::acquire_gil` will now only assume responsiblity for freeing owned references on drop if no other `GILPool` or `GILGuard` exists. This ensures that multiple calls to the safe api `Python::acquire_gil` cannot lead to dangling references. [#893](https://github.com/PyO3/pyo3/pull/893) -- The trait `ObjectProtocol` has been removed, and all the methods from the trait have been moved to `PyAny`. [#911](https://github.com/PyO3/pyo3/pull/911) - - The exception to this is `ObjectProtocol::None`, which has simply been removed. Use `Python::None` instead. -- No `#![feature(specialization)]` in user code. [#917](https://github.com/PyO3/pyo3/pull/917) +- Panics will now be raised as a Python `PanicException`. [#797](https://github.com/PyO3/pyo3/pull/797) +- Change `PyObject` and `Py` reference counts to decrement immediately upon drop when the GIL is held. [#851](https://github.com/PyO3/pyo3/pull/851) +- Allow `PyIterProtocol` methods to use either `PyRef` or `PyRefMut` as the receiver type. [#856](https://github.com/PyO3/pyo3/pull/856) +- Change the implementation of `FromPyObject` for `Py` to apply to a wider range of `T`, including all `T: PyClass`. [#880](https://github.com/PyO3/pyo3/pull/880) +- Move all methods from the `ObjectProtocol` trait to the `PyAny` struct. [#911](https://github.com/PyO3/pyo3/pull/911) +- Remove need for `#![feature(specialization)]` in crates depending on PyO3. [#917](https://github.com/PyO3/pyo3/pull/917) ### Removed -- `PyMethodsProtocol` is now renamed to `PyMethodsImpl` and hidden. [#889](https://github.com/PyO3/pyo3/pull/889) -- `num-traits` is no longer a dependency. [#895](https://github.com/PyO3/pyo3/pull/895) -- `ObjectProtocol`. [#911](https://github.com/PyO3/pyo3/pull/911) -- All `*ProtocolImpl` traits. [#917](https://github.com/PyO3/pyo3/pull/917) +- Remove `PyMethodsProtocol` trait. [#889](https://github.com/PyO3/pyo3/pull/889) +- Remove `num-traits` dependency. [#895](https://github.com/PyO3/pyo3/pull/895) +- Remove `ObjectProtocol` trait. [#911](https://github.com/PyO3/pyo3/pull/911) +- Remove `PyAny::None`. Users should use `Python::None` instead. [#911](https://github.com/PyO3/pyo3/pull/911) +- Remove all `*ProtocolImpl` traits. [#917](https://github.com/PyO3/pyo3/pull/917) ### Fixed -- `__radd__` and other `__r*__` methods now correctly work with operators. [#839](https://github.com/PyO3/pyo3/pull/839) -- Garbage Collector causing random panics when traversing objects that were mutably borrowed. [#855](https://github.com/PyO3/pyo3/pull/855) -- `&'static Py~` being allowed as arguments. [#869](https://github.com/PyO3/pyo3/pull/869) -- `#[pyo3(get)]` for `Py`. [#880](https://github.com/PyO3/pyo3/pull/880) -- `allow_threads` will no longer cause segfaults in the event of panics inside the closure. [#912](https://github.com/PyO3/pyo3/pull/912) +- Fix support for `__radd__` and other `__r*__` methods as implementations for Python mathematical operators. [#839](https://github.com/PyO3/pyo3/pull/839) +- Fix panics during garbage collection when traversing objects that were already mutably borrowed. [#855](https://github.com/PyO3/pyo3/pull/855) +- Prevent `&'static` references to Python objects as arguments to `#[pyfunction]` and `#[pymethods]`. [#869](https://github.com/PyO3/pyo3/pull/869) +- Fix lifetime safety bug with `AsPyRef::as_ref`. [#876](https://github.com/PyO3/pyo3/pull/876) +- Fix `#[pyo3(get)]` attribute on `Py` fields. [#880](https://github.com/PyO3/pyo3/pull/880) +- Fix segmentation faults caused by functions such as `PyList::get_item` returning borrowed objects when it was not safe to do so. [#890](https://github.com/PyO3/pyo3/pull/890) +- Fix segmentation faults caused by nested `Python::acquire_gil` calls creating dangling references. [#893](https://github.com/PyO3/pyo3/pull/893) +- Fix segmentatation faults when a panic occurs during a call to `Python::allow_threads`. [#912](https://github.com/PyO3/pyo3/pull/912) ## [0.9.2] - 2020-04-09 ### Added @@ -385,7 +389,8 @@ Yanked ### Added - Initial release -[Unreleased]: https://github.com/pyo3/pyo3/compare/v0.9.2...HEAD +[Unreleased]: https://github.com/pyo3/pyo3/compare/v0.10.0...HEAD +[0.10.0]: https://github.com/pyo3/pyo3/compare/v0.9.2...v0.10.0 [0.9.2]: https://github.com/pyo3/pyo3/compare/v0.9.1...v0.9.2 [0.9.1]: https://github.com/pyo3/pyo3/compare/v0.9.0...v0.9.1 [0.9.0]: https://github.com/pyo3/pyo3/compare/v0.8.5...v0.9.0 diff --git a/Cargo.toml b/Cargo.toml index 56f831f5..e12e718e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3" -version = "0.9.2" +version = "0.10.0" description = "Bindings to Python interpreter" authors = ["PyO3 Project and Contributors "] readme = "README.md" @@ -25,7 +25,7 @@ libc = "0.2.62" num-bigint = { version = "0.2", optional = true } num-complex = { version = "0.2", optional = true } paste = { version = "0.1.6", optional = true } -pyo3cls = { path = "pyo3cls", version = "=0.9.2", optional = true } +pyo3cls = { path = "pyo3cls", version = "=0.10.0", optional = true } unindent = { version = "0.1.4", optional = true } [dev-dependencies] diff --git a/README.md b/README.md index dda19fd2..a4d99ade 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ name = "string_sum" crate-type = ["cdylib"] [dependencies.pyo3] -version = "0.9.2" +version = "0.10.0" features = ["extension-module"] ``` @@ -95,7 +95,7 @@ Add `pyo3` to your `Cargo.toml` like this: ```toml [dependencies] -pyo3 = "0.9.2" +pyo3 = "0.10.0" ``` Example program displaying the value of `sys.version` and the current user name: diff --git a/guide/src/get_started.md b/guide/src/get_started.md index 2a17b85c..5f79af25 100644 --- a/guide/src/get_started.md +++ b/guide/src/get_started.md @@ -44,7 +44,7 @@ name = "string_sum" crate-type = ["cdylib"] [dependencies.pyo3] -version = "0.9.2" +version = "0.10.0" features = ["extension-module"] ``` @@ -90,7 +90,7 @@ use it to run Python code, add `pyo3` to your `Cargo.toml` like this: ```toml [dependencies] -pyo3 = "0.9.2" +pyo3 = "0.10.0" ``` Example program displaying the value of `sys.version` and the current user name: diff --git a/guide/src/migration.md b/guide/src/migration.md index 4035d89c..5aa2352e 100644 --- a/guide/src/migration.md +++ b/guide/src/migration.md @@ -1,5 +1,38 @@ # Appendix B: Migrating from older PyO3 versions -This guide can help you upgrade code through breaking changes from one PyO3 version to the next. For a detailed list of all changes, see [CHANGELOG.md](https://github.com/PyO3/pyo3/blob/master/CHANGELOG.md) + +This guide can help you upgrade code through breaking changes from one PyO3 version to the next. +For a detailed list of all changes, see [CHANGELOG.md](https://github.com/PyO3/pyo3/blob/master/CHANGELOG.md) + +## from 0.9.* to 0.10 + +### `ObjectProtocol` is removed +All methods are moved to [`PyAny`]. +And since now all native types (e.g., `PyList`) implements `Deref`, +all you need to do is remove `ObjectProtocol` from your code. +Or if you use `ObjectProtocol` by `use pyo3::prelude::*`, you have to do nothing. + +Before: +```rust,compile_fail +use pyo3::ObjectProtocol; + +let gil = pyo3::Python::acquire_gil(); +let obj = gil.python().eval("lambda: 'Hi :)'", None, None).unwrap(); +let hi: &pyo3::types::PyString = obj.call0().unwrap().downcast().unwrap(); +assert_eq!(hi.len().unwrap(), 5); +``` + +After: +```rust +let gil = pyo3::Python::acquire_gil(); +let obj = gil.python().eval("lambda: 'Hi :)'", None, None).unwrap(); +let hi: &pyo3::types::PyString = obj.call0().unwrap().downcast().unwrap(); +assert_eq!(hi.len().unwrap(), 5); +``` + +### No `#![feature(specialization)]` in user code +While PyO3 itself still requires specialization and nightly Rust, +now you don't have to use `#![feature(specialization)]` in your crate. + ## from 0.8.* to 0.9 ### `#[new]` interface @@ -191,10 +224,10 @@ impl PySequenceProtocol for ByteSequence { ``` [`FromPyObject`]: https://docs.rs/pyo3/latest/pyo3/conversion/trait.FromPyObject.html - -[`PyCell`]: https://pyo3.rs/master/doc/pyo3/pycell/struct.PyCell.html -[`PyBorrowMutError`]: https://pyo3.rs/master/doc/pyo3/pycell/struct.PyBorrowMutError.html -[`PyRef`]: https://pyo3.rs/master/doc/pyo3/pycell/struct.PyRef.html -[`PyRefMut`]: https://pyo3.rs/master/doc/pyo3/pycell/struct.PyRefMut.html +[`PyAny`]: https://docs.rs/pyo3/latest/pyo3/types/struct.PyAny.html +[`PyCell`]: https://docs.rs/pyo3/latest/pyo3/pycell/struct.PyCell.html +[`PyBorrowMutError`]: https://docs.rs/pyo3/latest/pyo3/pycell/struct.PyBorrowMutError.html +[`PyRef`]: https://docs.rs/pyo3/latest/pyo3/pycell/struct.PyRef.html +[`PyRefMut`]: https://docs.rs/pyo3/latest/pyo3/pycell/struct.PyRef.html [`RefCell`]: https://doc.rust-lang.org/std/cell/struct.RefCell.html diff --git a/pyo3-derive-backend/Cargo.toml b/pyo3-derive-backend/Cargo.toml index b2c7ded1..95cb4271 100644 --- a/pyo3-derive-backend/Cargo.toml +++ b/pyo3-derive-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-derive-backend" -version = "0.9.2" +version = "0.10.0" description = "Code generation for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] diff --git a/pyo3cls/Cargo.toml b/pyo3cls/Cargo.toml index 28820b7d..f6e8a95b 100644 --- a/pyo3cls/Cargo.toml +++ b/pyo3cls/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3cls" -version = "0.9.2" +version = "0.10.0" description = "Proc macros for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -16,4 +16,4 @@ proc-macro = true [dependencies] quote = "1" syn = { version = "1", features = ["full", "extra-traits"] } -pyo3-derive-backend = { path = "../pyo3-derive-backend", version = "=0.9.2" } +pyo3-derive-backend = { path = "../pyo3-derive-backend", version = "=0.10.0" } diff --git a/src/lib.rs b/src/lib.rs index 07ae99ec..edb28423 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ //! crate-type = ["cdylib"] //! //! [dependencies.pyo3] -//! version = "0.9.2" +//! version = "0.10.0" //! features = ["extension-module"] //! ``` //! @@ -109,7 +109,7 @@ //! //! ```toml //! [dependencies] -//! pyo3 = "0.9.2" +//! pyo3 = "0.10.0" //! ``` //! //! Example program displaying the value of `sys.version`: