diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a9838e7eb5..1b8975d79a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,40 @@ To see unreleased changes, please see the [CHANGELOG on the main branch guide](h +## [0.22.3] - 2024-09-15 + +### Added + +- Add `pyo3::ffi::compat` namespace with compatibility shims for C API functions added in recent versions of Python. +- Add FFI definition `PyDict_GetItemRef` on Python 3.13 and newer, and `compat::PyDict_GetItemRef` for all versions. [#4355](https://github.com/PyO3/pyo3/pull/4355) +- Add FFI definition `PyList_GetItemRef` on Python 3.13 and newer, and `pyo3_ffi::compat::PyList_GetItemRef` for all versions. [#4410](https://github.com/PyO3/pyo3/pull/4410) +- Add FFI definitions `compat::Py_NewRef` and `compat::Py_XNewRef`. [#4445](https://github.com/PyO3/pyo3/pull/4445) +- Add FFI definitions `compat::PyObject_CallNoArgs` and `compat::PyObject_CallMethodNoArgs`. [#4461](https://github.com/PyO3/pyo3/pull/4461) +- Add `GilOnceCell>::clone_ref`. [#4511](https://github.com/PyO3/pyo3/pull/4511) + +### Changed + +- Improve error messages for `#[pyfunction]` defined inside `#[pymethods]`. [#4349](https://github.com/PyO3/pyo3/pull/4349) +- Improve performance of calls to Python by using the vectorcall calling convention where possible. [#4456](https://github.com/PyO3/pyo3/pull/4456) +- Mention the type name in the exception message when trying to instantiate a class with no constructor defined. [#4481](https://github.com/PyO3/pyo3/pull/4481) + +### Removed + +- Remove private FFI definition `_Py_PackageContext`. [#4420](https://github.com/PyO3/pyo3/pull/4420) + +### Fixed + +- Fix compile failure in declarative `#[pymodule]` under presence of `#![no_implicit_prelude]`. [#4328](https://github.com/PyO3/pyo3/pull/4328) +- Fix use of borrowed reference in `PyDict::get_item` (unsafe in free-threaded Python). [#4355](https://github.com/PyO3/pyo3/pull/4355) +- Fix `#[pyclass(eq)]` macro hygiene issues for structs and enums. [#4359](https://github.com/PyO3/pyo3/pull/4359) +- Fix hygiene/span issues of `'#[pyfunction]` and `#[pymethods]` generated code which affected expansion in `macro_rules` context. [#4382](https://github.com/PyO3/pyo3/pull/4382) +- Fix `unsafe_code` lint error in `#[pyclass]` generated code. [#4396](https://github.com/PyO3/pyo3/pull/4396) +- Fix async functions returning a tuple only returning the first element to Python. [#4407](https://github.com/PyO3/pyo3/pull/4407) +- Fix use of borrowed reference in `PyList::get_item` (unsafe in free-threaded Python). [#4410](https://github.com/PyO3/pyo3/pull/4410) +- Correct FFI definition `PyArg_ParseTupleAndKeywords` to take `*const *const c_char` instead of `*mut *mut c_char` on Python 3.13 and up. [#4420](https://github.com/PyO3/pyo3/pull/4420) +- Fix a soundness bug with `PyClassInitializer`: panic if adding subclass to existing instance via `PyClassInitializer::from(Py).add_subclass(SubClass)`. [#4454](https://github.com/PyO3/pyo3/pull/4454) +- Fix illegal reference counting op inside implementation of `__traverse__` handlers. [#4479](https://github.com/PyO3/pyo3/pull/4479) + ## [0.22.2] - 2024-07-17 ### Packaging diff --git a/Cargo.toml b/Cargo.toml index 29e131dd827..ee260f1bfc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3" -version = "0.22.2" +version = "0.22.3" description = "Bindings to Python interpreter" authors = ["PyO3 Project and Contributors "] readme = "README.md" @@ -21,10 +21,10 @@ memoffset = "0.9" once_cell = "1.13" # ffi bindings to the python interpreter, split into a separate crate so they can be used independently -pyo3-ffi = { path = "pyo3-ffi", version = "=0.22.2" } +pyo3-ffi = { path = "pyo3-ffi", version = "=0.22.3" } # support crates for macros feature -pyo3-macros = { path = "pyo3-macros", version = "=0.22.2", optional = true } +pyo3-macros = { path = "pyo3-macros", version = "=0.22.3", optional = true } indoc = { version = "2.0.1", optional = true } unindent = { version = "0.2.1", optional = true } @@ -64,7 +64,7 @@ futures = "0.3.28" static_assertions = "1.1.0" [build-dependencies] -pyo3-build-config = { path = "pyo3-build-config", version = "=0.22.2", features = ["resolve-config"] } +pyo3-build-config = { path = "pyo3-build-config", version = "=0.22.3", features = ["resolve-config"] } [features] default = ["macros"] diff --git a/README.md b/README.md index 2a6348437a2..198872acf85 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ name = "string_sum" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.22.2", features = ["extension-module"] } +pyo3 = { version = "0.22.3", features = ["extension-module"] } ``` **`src/lib.rs`** @@ -137,7 +137,7 @@ Start a new project with `cargo new` and add `pyo3` to the `Cargo.toml` like th ```toml [dependencies.pyo3] -version = "0.22.2" +version = "0.22.3" features = ["auto-initialize"] ``` diff --git a/examples/decorator/.template/pre-script.rhai b/examples/decorator/.template/pre-script.rhai index a9f0eb4a289..32b20a55d17 100644 --- a/examples/decorator/.template/pre-script.rhai +++ b/examples/decorator/.template/pre-script.rhai @@ -1,4 +1,4 @@ -variable::set("PYO3_VERSION", "0.22.2"); +variable::set("PYO3_VERSION", "0.22.3"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/pyproject.toml", "pyproject.toml"); file::delete(".template"); diff --git a/examples/maturin-starter/.template/pre-script.rhai b/examples/maturin-starter/.template/pre-script.rhai index a9f0eb4a289..32b20a55d17 100644 --- a/examples/maturin-starter/.template/pre-script.rhai +++ b/examples/maturin-starter/.template/pre-script.rhai @@ -1,4 +1,4 @@ -variable::set("PYO3_VERSION", "0.22.2"); +variable::set("PYO3_VERSION", "0.22.3"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/pyproject.toml", "pyproject.toml"); file::delete(".template"); diff --git a/examples/plugin/.template/pre-script.rhai b/examples/plugin/.template/pre-script.rhai index bbc96358a23..ee37346e10d 100644 --- a/examples/plugin/.template/pre-script.rhai +++ b/examples/plugin/.template/pre-script.rhai @@ -1,4 +1,4 @@ -variable::set("PYO3_VERSION", "0.22.2"); +variable::set("PYO3_VERSION", "0.22.3"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/plugin_api/Cargo.toml", "plugin_api/Cargo.toml"); file::delete(".template"); diff --git a/examples/setuptools-rust-starter/.template/pre-script.rhai b/examples/setuptools-rust-starter/.template/pre-script.rhai index d28d9d09987..8ceb8df28bb 100644 --- a/examples/setuptools-rust-starter/.template/pre-script.rhai +++ b/examples/setuptools-rust-starter/.template/pre-script.rhai @@ -1,4 +1,4 @@ -variable::set("PYO3_VERSION", "0.22.2"); +variable::set("PYO3_VERSION", "0.22.3"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/setup.cfg", "setup.cfg"); file::delete(".template"); diff --git a/examples/word-count/.template/pre-script.rhai b/examples/word-count/.template/pre-script.rhai index a9f0eb4a289..32b20a55d17 100644 --- a/examples/word-count/.template/pre-script.rhai +++ b/examples/word-count/.template/pre-script.rhai @@ -1,4 +1,4 @@ -variable::set("PYO3_VERSION", "0.22.2"); +variable::set("PYO3_VERSION", "0.22.3"); file::rename(".template/Cargo.toml", "Cargo.toml"); file::rename(".template/pyproject.toml", "pyproject.toml"); file::delete(".template"); diff --git a/newsfragments/4328.fixed.md b/newsfragments/4328.fixed.md deleted file mode 100644 index f21fdfbcb76..00000000000 --- a/newsfragments/4328.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fix compile failure in declarative `#[pymodule]` under presence of `#![no_implicit_prelude]`. diff --git a/newsfragments/4349.fixed.md b/newsfragments/4349.fixed.md deleted file mode 100644 index 0895ffa1ae1..00000000000 --- a/newsfragments/4349.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Improve error messages for `#[pyfunction]` defined inside `#[pymethods]` diff --git a/newsfragments/4355.added.md b/newsfragments/4355.added.md deleted file mode 100644 index 1410c0720bf..00000000000 --- a/newsfragments/4355.added.md +++ /dev/null @@ -1,10 +0,0 @@ -* Added an `ffi::compat` namespace to store compatibility shims for C API - functions added in recent versions of Python. - -* Added bindings for `PyDict_GetItemRef` on Python 3.13 and newer. Also added - `ffi::compat::PyDict_GetItemRef` which re-exports the FFI binding on Python - 3.13 or newer and defines a compatibility version on older versions of - Python. This function is inherently safer to use than `PyDict_GetItem` and has - an API that is easier to use than `PyDict_GetItemWithError`. It returns a - strong reference to value, as opposed to the two older functions which return - a possibly unsafe borrowed reference. diff --git a/newsfragments/4355.fixed.md b/newsfragments/4355.fixed.md deleted file mode 100644 index 9a141bc6b96..00000000000 --- a/newsfragments/4355.fixed.md +++ /dev/null @@ -1,2 +0,0 @@ -Avoid creating temporary borrowed reference in dict.get_item bindings. Borrowed -references like this are unsafe in the free-threading build. diff --git a/newsfragments/4359.fixed.md b/newsfragments/4359.fixed.md deleted file mode 100644 index 7174cab0a9d..00000000000 --- a/newsfragments/4359.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fixed `pyclass` macro hygiene issues for structs and enums and added tests. \ No newline at end of file diff --git a/newsfragments/4382.fixed.md b/newsfragments/4382.fixed.md deleted file mode 100644 index 974ae23d3bf..00000000000 --- a/newsfragments/4382.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fixed hygiene/span issues of emitted code which affected expansion in `macro_rules` context. \ No newline at end of file diff --git a/newsfragments/4396.fixed.md b/newsfragments/4396.fixed.md deleted file mode 100644 index 285358ad526..00000000000 --- a/newsfragments/4396.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Hide confusing warnings about unsafe usage in `#[pyclass]` implementation. diff --git a/newsfragments/4407.fixed.md b/newsfragments/4407.fixed.md deleted file mode 100644 index be2706bca05..00000000000 --- a/newsfragments/4407.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fix async functions returning a tuple only returning the first element to Python. diff --git a/newsfragments/4410.added.md b/newsfragments/4410.added.md deleted file mode 100644 index 350a54531bd..00000000000 --- a/newsfragments/4410.added.md +++ /dev/null @@ -1 +0,0 @@ -Add ffi binding `PyList_GetItemRef` and `pyo3_ffi::compat::PyList_GetItemRef` diff --git a/newsfragments/4410.fixed.md b/newsfragments/4410.fixed.md deleted file mode 100644 index f4403409aea..00000000000 --- a/newsfragments/4410.fixed.md +++ /dev/null @@ -1,3 +0,0 @@ -* Avoid creating temporary borrowed reference in list.get_item - bindings. Temporary borrowed references are unsafe in the free-threaded python - build if the list is shared between threads. diff --git a/newsfragments/4420.fixed.md b/newsfragments/4420.fixed.md deleted file mode 100644 index dec974555d9..00000000000 --- a/newsfragments/4420.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Correct FFI definition `PyArg_ParseTupleAndKeywords` to take `*const *const c_char` instead of `*mut *mut c_char` on Python 3.13 and up. diff --git a/newsfragments/4420.removed.md b/newsfragments/4420.removed.md deleted file mode 100644 index 9d17c33e143..00000000000 --- a/newsfragments/4420.removed.md +++ /dev/null @@ -1 +0,0 @@ -Remove FFI definition of private variable `_Py_PackageContext`. diff --git a/newsfragments/4445.added.md b/newsfragments/4445.added.md deleted file mode 100644 index ee6af52d97e..00000000000 --- a/newsfragments/4445.added.md +++ /dev/null @@ -1 +0,0 @@ -Add FFI definitions `compat::Py_NewRef` and `compat::Py_XNewRef`. diff --git a/newsfragments/4445.removed.md b/newsfragments/4445.removed.md deleted file mode 100644 index b5b7e450331..00000000000 --- a/newsfragments/4445.removed.md +++ /dev/null @@ -1 +0,0 @@ -Remove private FFI definitions `_Py_NewRef` and `_Py_XNewRef`. diff --git a/newsfragments/4454.fixed.md b/newsfragments/4454.fixed.md deleted file mode 100644 index e7faf3e690d..00000000000 --- a/newsfragments/4454.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fix a soundness bug with `PyClassInitializer`: from now you cannot initialize a `PyClassInitializer` with `PyClassInitializer::from(Py).add_subclass(SubClass)`. \ No newline at end of file diff --git a/newsfragments/4456.changed.md b/newsfragments/4456.changed.md deleted file mode 100644 index 094dece12a5..00000000000 --- a/newsfragments/4456.changed.md +++ /dev/null @@ -1 +0,0 @@ -Improve performance of calls to Python by using the vectorcall calling convention where possible. \ No newline at end of file diff --git a/newsfragments/4461.added.md b/newsfragments/4461.added.md deleted file mode 100644 index c151664c843..00000000000 --- a/newsfragments/4461.added.md +++ /dev/null @@ -1 +0,0 @@ -Add FFI definitions `compat::PyObject_CallNoArgs` and `compat::PyObject_CallMethodNoArgs`. diff --git a/newsfragments/4479.fixed.md b/newsfragments/4479.fixed.md deleted file mode 100644 index 15d634543af..00000000000 --- a/newsfragments/4479.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Remove illegal reference counting op inside implementation of `__traverse__` handlers. diff --git a/newsfragments/4481.changed.md b/newsfragments/4481.changed.md deleted file mode 100644 index 9ce455c923c..00000000000 --- a/newsfragments/4481.changed.md +++ /dev/null @@ -1 +0,0 @@ -Mention the type name in the exception message when trying to instantiate a class with no constructor defined. diff --git a/newsfragments/4511.added.md b/newsfragments/4511.added.md deleted file mode 100644 index 6572ddc7238..00000000000 --- a/newsfragments/4511.added.md +++ /dev/null @@ -1 +0,0 @@ -Add Python-ref cloning `clone_ref` for `GILOnceCell>` diff --git a/pyo3-build-config/Cargo.toml b/pyo3-build-config/Cargo.toml index e7b180facff..2140592312a 100644 --- a/pyo3-build-config/Cargo.toml +++ b/pyo3-build-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-build-config" -version = "0.22.2" +version = "0.22.3" description = "Build configuration for the PyO3 ecosystem" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] diff --git a/pyo3-ffi/Cargo.toml b/pyo3-ffi/Cargo.toml index 8b350926205..bbd5ac26100 100644 --- a/pyo3-ffi/Cargo.toml +++ b/pyo3-ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-ffi" -version = "0.22.2" +version = "0.22.3" description = "Python-API bindings for the PyO3 ecosystem" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -41,7 +41,7 @@ generate-import-lib = ["pyo3-build-config/python3-dll-a"] paste = "1" [build-dependencies] -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.2", features = ["resolve-config"] } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.3", features = ["resolve-config"] } [lints] workspace = true diff --git a/pyo3-macros-backend/Cargo.toml b/pyo3-macros-backend/Cargo.toml index 09a662becd2..a9d3ac92d2a 100644 --- a/pyo3-macros-backend/Cargo.toml +++ b/pyo3-macros-backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-macros-backend" -version = "0.22.2" +version = "0.22.3" description = "Code generation for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -16,7 +16,7 @@ edition = "2021" [dependencies] heck = "0.5" proc-macro2 = { version = "1.0.60", default-features = false } -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.2", features = ["resolve-config"] } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.3", features = ["resolve-config"] } quote = { version = "1", default-features = false } [dependencies.syn] @@ -25,7 +25,7 @@ default-features = false features = ["derive", "parsing", "printing", "clone-impls", "full", "extra-traits"] [build-dependencies] -pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.2" } +pyo3-build-config = { path = "../pyo3-build-config", version = "=0.22.3" } [lints] workspace = true diff --git a/pyo3-macros/Cargo.toml b/pyo3-macros/Cargo.toml index 98003c67272..eb1ae6ded97 100644 --- a/pyo3-macros/Cargo.toml +++ b/pyo3-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-macros" -version = "0.22.2" +version = "0.22.3" description = "Proc macros for PyO3 package" authors = ["PyO3 Project and Contributors "] keywords = ["pyo3", "python", "cpython", "ffi"] @@ -22,7 +22,7 @@ gil-refs = ["pyo3-macros-backend/gil-refs"] proc-macro2 = { version = "1.0.60", default-features = false } quote = "1" syn = { version = "2", features = ["full", "extra-traits"] } -pyo3-macros-backend = { path = "../pyo3-macros-backend", version = "=0.22.2" } +pyo3-macros-backend = { path = "../pyo3-macros-backend", version = "=0.22.3" } [lints] workspace = true diff --git a/pyproject.toml b/pyproject.toml index c5c4c9261e7..585b822d4bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [tool.towncrier] filename = "CHANGELOG.md" -version = "0.22.2" +version = "0.22.3" start_string = "\n" template = ".towncrier.template.md" title_format = "## [{version}] - {project_date}" diff --git a/tests/ui/reject_generics.stderr b/tests/ui/reject_generics.stderr index 7379299aea4..bab410cc25d 100644 --- a/tests/ui/reject_generics.stderr +++ b/tests/ui/reject_generics.stderr @@ -1,10 +1,10 @@ -error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.22.2/class.html#no-generic-parameters +error: #[pyclass] cannot have generic parameters. For an explanation, see https://pyo3.rs/v0.22.3/class.html#no-generic-parameters --> tests/ui/reject_generics.rs:4:25 | 4 | struct ClassWithGenerics { | ^ -error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.22.2/class.html#no-lifetime-parameters +error: #[pyclass] cannot have lifetime parameters. For an explanation, see https://pyo3.rs/v0.22.3/class.html#no-lifetime-parameters --> tests/ui/reject_generics.rs:9:27 | 9 | struct ClassWithLifetimes<'a> {