Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pyo3 to v0.22 and update code to use pyo3 Bound types #123

Merged
merged 4 commits into from
Aug 2, 2024

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Mar 26, 2024

Mend Renovate

This PR contains the following updates:

Package Type Update Change
pyo3 dependencies minor =0.20.3 -> =0.22.2

Release Notes

pyo3/pyo3 (pyo3)

v0.22.2: PyO3 0.22.2

Compare Source

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

v0.22.1

Compare Source

Added
  • Add #[pyo3(submodule)] option for declarative #[pymodule]s. #​4301
  • Implement PartialEq<bool> for Bound<'py, PyBool>. #​4305
Fixed
  • Return NotImplemented instead of raising TypeError from generated equality method when comparing different types. #​4287
  • Handle full-path #[pyo3::prelude::pymodule] and similar for #[pyclass] and #[pyfunction] in declarative modules.#​4288
  • Fix 128-bit int regression on big-endian platforms with Python <3.13. #​4291
  • Stop generating code that will never be covered with declarative modules. #​4297
  • Fix invalid deprecation warning for trailing optional on #[setter] function. #​4304

v0.22.0

Compare Source

Packaging
  • Update heck dependency to 0.5. #​3966
  • Extend range of supported versions of chrono-tz optional dependency to include version 0.10. #​4061
  • Update MSRV to 1.63. #​4129
  • Add optional num-rational feature to add conversions with Python's fractions.Fraction. #​4148
  • Support Python 3.13. #​4184
Added
  • Add PyWeakref, PyWeakrefReference and PyWeakrefProxy. #​3835
  • Support #[pyclass] on enums that have tuple variants. #​4072
  • Add support for scientific notation in Decimal conversion. #​4079
  • Add pyo3_disable_reference_pool conditional compilation flag to avoid the overhead of the global reference pool at the cost of known limitations as explained in the performance section of the guide. #​4095
  • Add #[pyo3(constructor = (...))] to customize the generated constructors for complex enum variants. #​4158
  • Add PyType::module, which always matches Python __module__. #​4196
  • Add PyType::fully_qualified_name which matches the "fully qualified name" defined in PEP 737. #​4196
  • Add PyTypeMethods::mro and PyTypeMethods::bases. #​4197
  • Add #[pyclass(ord)] to implement ordering based on PartialOrd. #​4202
  • Implement ToPyObject and IntoPy<PyObject> for PyBackedStr and PyBackedBytes. #​4205
  • Add #[pyclass(hash)] option to implement __hash__ in terms of the Hash implementation #​4206
  • Add #[pyclass(eq)] option to generate __eq__ based on PartialEq, and #[pyclass(eq_int)] for simple enums to implement equality based on their discriminants. #​4210
  • Implement From<Bound<'py, T>> for PyClassInitializer<T>. #​4214
  • Add as_super methods to PyRef and PyRefMut for accesing the base class by reference. #​4219
  • Implement PartialEq<str> for Bound<'py, PyString>. #​4245
  • Implement PyModuleMethods::filename on PyPy. #​4249
  • Implement PartialEq<[u8]> for Bound<'py, PyBytes>. #​4250
  • Add pyo3_ffi::c_str macro to create &'static CStr on Rust versions which don't have 1.77's c"" literals. #​4255
  • Support bool conversion with numpy 2.0's numpy.bool type #​4258
  • Add PyAnyMethods::{bitnot, matmul, floor_div, rem, divmod}. #​4264
Changed
  • Change the type of PySliceIndices::slicelength and the length parameter of PySlice::indices(). #​3761
  • Deprecate implicit default for trailing optional arguments #​4078
  • Cloneing pointers into the Python heap has been moved behind the py-clone feature, as it must panic without the GIL being held as a soundness fix. #​4095
  • Add #[track_caller] to all Py<T>, Bound<'py, T> and Borrowed<'a, 'py, T> methods which can panic. #​4098
  • Change PyAnyMethods::dir to be fallible and return PyResult<Bound<'py, PyList>> (and similar for PyAny::dir). #​4100
  • The global reference pool (to track pending reference count decrements) is now initialized lazily to avoid the overhead of taking a mutex upon function entry when the functionality is not actually used. #​4178
  • Emit error messages when using weakref or dict when compiling for abi3 for Python older than 3.9. #​4194
  • Change PyType::name to always match Python __name__. #​4196
  • Remove CPython internal ffi call for complex number including: add, sub, mul, div, neg, abs, pow. Added PyAnyMethods::{abs, pos, neg} #​4201
  • Deprecate implicit integer comparision for simple enums in favor of #[pyclass(eq_int)]. #​4210
  • Set the module= attribute of declarative modules' child #[pymodule]s and #[pyclass]es. #​4213
  • Set the module option for complex enum variants from the value set on the complex enum module. #​4228
  • Respect the Python "limited API" when building for the abi3 feature on PyPy or GraalPy. #​4237
  • Optimize code generated by #[pyo3(get)] on #[pyclass] fields. #​4254
  • PyCFunction::new, PyCFunction::new_with_keywords and PyCFunction::new_closure now take &'static CStr name and doc arguments (previously was &'static str). #​4255
  • The experimental-declarative-modules feature is now stabilized and available by default. #​4257
Fixed
  • Fix panic when PYO3_CROSS_LIB_DIR is set to a missing path. #​4043
  • Fix a compile error when exporting an exception created with create_exception! living in a different Rust module using the declarative-module feature. #​4086
  • Fix FFI definitions of PY_VECTORCALL_ARGUMENTS_OFFSET and PyVectorcall_NARGS to fix a false-positive assertion. #​4104
  • Disable PyUnicode_DATA on PyPy: not exposed by PyPy. #​4116
  • Correctly handle #[pyo3(from_py_with = ...)] attribute on dunder (__magic__) method arguments instead of silently ignoring it. #​4117
  • Fix a compile error when declaring a standalone function or class method with a Python name that is a Rust keyword. #​4226
  • Fix declarative modules discarding doc comments on the mod node. #​4236
  • Fix __dict__ attribute missing for #[pyclass(dict)] instances when building for abi3 on Python 3.9. #​4251

v0.21.2

Compare Source

Changed
  • Deprecate the PySet::empty() gil-ref constructor. #​4082
Fixed
  • Fix compile error for async fn in #[pymethods] with a &self receiver and more than one additional argument. #​4035
  • Improve error message for wrong receiver type in __traverse__. #​4045
  • Fix compile error when exporting a #[pyclass] living in a different Rust module using the experimental-declarative-modules feature. #​4054
  • Fix missing_docs lint triggering on documented #[pymodule] functions. #​4067
  • Fix undefined symbol errors for extension modules on AIX (by linking libpython). #​4073

v0.21.1

Compare Source

Added
  • Implement Send and Sync for PyBackedStr and PyBackedBytes. #​4007
  • Implement Clone, Debug, PartialEq, Eq, PartialOrd, Ord and Hash implementation for PyBackedBytes and PyBackedStr, and Display for PyBackedStr. #​4020
  • Add import_exception_bound! macro to import exception types without generating GIL Ref functionality for them. #​4027
Changed
  • Emit deprecation warning for uses of GIL Refs as #[setter] function arguments. #​3998
  • Add #[inline] hints on many Bound and Borrowed methods. #​4024
Fixed
  • Handle #[pyo3(from_py_with = "")] in #[setter] methods #​3995
  • Allow extraction of &Bound in #[setter] methods. #​3998
  • Fix some uncovered code blocks emitted by #[pymodule], #[pyfunction] and #[pyclass] macros. #​4009
  • Fix typo in the panic message when a class referenced in pyo3::import_exception! does not exist. #​4012
  • Fix compile error when using an async #[pymethod] with a receiver and additional arguments. #​4015

v0.21.0

Compare Source

Added
  • Add support for GraalPy (24.0 and up). #​3247
  • Add PyMemoryView type. #​3514
  • Allow async fn in for #[pyfunction] and #[pymethods], with the experimental-async feature. #​3540 #​3588 #​3599 #​3931
  • Implement PyTypeInfo for PyEllipsis, PyNone and PyNotImplemented. #​3577
  • Support #[pyclass] on enums that have non-unit variants. #​3582
  • Support chrono feature with abi3 feature. #​3664
  • FromPyObject, IntoPy<PyObject> and ToPyObject are implemented on std::duration::Duration #​3670
  • Add PyString::to_cow. Add Py<PyString>::to_str, Py<PyString>::to_cow, and Py<PyString>::to_string_lossy, as ways to access Python string data safely beyond the GIL lifetime. #​3677
  • Add Bound<T> and Borrowed<T> smart pointers as a new API for accessing Python objects. #​3686
  • Add PyNativeType::as_borrowed to convert "GIL refs" to the new Bound smart pointer. #​3692
  • Add FromPyObject::extract_bound method, to migrate FromPyObject implementations to the Bound API. #​3706
  • Add gil-refs feature to allow continued use of the deprecated GIL Refs APIs. #​3707
  • Add methods to PyAnyMethods for binary operators (add, sub, etc.) #​3712
  • Add chrono-tz feature allowing conversion between chrono_tz::Tz and zoneinfo.ZoneInfo #​3730
  • Add FFI definition PyType_GetModuleByDef. #​3734
  • Conversion between std::time::SystemTime and datetime.datetime #​3736
  • Add Py::as_any and Py::into_any. #​3785
  • Add PyStringMethods::encode_utf8. #​3801
  • Add PyBackedStr and PyBackedBytes, as alternatives to &str and &bytes where a Python object owns the data. #​3802 #​3991
  • Allow #[pymodule] macro on Rust mod blocks, with the experimental-declarative-modules feature. #​3815
  • Implement ExactSizeIterator for set and frozenset iterators on abi3 feature. #​3849
  • Add Py::drop_ref to explicitly drop a `Py`` and immediately decrease the Python reference count if the GIL is already held. #​3871
  • Allow #[pymodule] macro on single argument functions that take &Bound<'_, PyModule>. #​3905
  • Implement FromPyObject for Cow<str>. #​3928
  • Implement Default for GILOnceCell. #​3971
  • Add PyDictMethods::into_mapping, PyListMethods::into_sequence and PyTupleMethods::into_sequence. #​3982
Changed
  • PyDict::from_sequence now takes a single argument of type &PyAny (previously took two arguments Python and PyObject). #​3532
  • Deprecate Py::is_ellipsis and PyAny::is_ellipsis in favour of any.is(py.Ellipsis()). #​3577
  • Split some PyTypeInfo functionality into new traits HasPyGilRef and PyTypeCheck. #​3600
  • Deprecate PyTryFrom and PyTryInto traits in favor of any.downcast() via the PyTypeCheck and PyTypeInfo traits. #​3601
  • Allow async methods to accept &self/&mut self #​3609
  • FromPyObject for set types now also accept frozenset objects as input. #​3632
  • FromPyObject for bool now also accepts NumPy's bool_ as input. #​3638
  • Add AsRefSource associated type to PyNativeType. #​3653
  • Rename .is_true to .is_truthy on PyAny and Py<PyAny> to clarify that the test is not based on identity with or equality to the True singleton. #​3657
  • PyType::name is now PyType::qualname whereas PyType::name efficiently accesses the full name which includes the module name. #​3660
  • The Iter(A)NextOutput types are now deprecated and __(a)next__ can directly return anything which can be converted into Python objects, i.e. awaitables do not need to be wrapped into IterANextOutput or Option any more. Option can still be used as well and returning None will trigger the fast path for __next__, stopping iteration without having to raise a StopIteration exception. #​3661
  • Implement FromPyObject on chrono::DateTime<Tz> for all Tz, not just FixedOffset and Utc. #​3663
  • Add lifetime parameter to PyTzInfoAccess trait. For the deprecated gil-ref API, the trait is now implemented for &'py PyTime and &'py PyDateTime instead of PyTime and PyDate. #​3679
  • Calls to __traverse__ become no-ops for unsendable pyclasses if on the wrong thread, thereby avoiding hard aborts at the cost of potential leakage. #​3689
  • Include PyNativeType in pyo3::prelude. #​3692
  • Improve performance of extract::<i64> (and other integer types) by avoiding call to __index__() converting the value to an integer for 3.10+. Gives performance improvement of around 30% for successful extraction. #​3742
  • Relax bound of FromPyObject for Py<T> to just T: PyTypeCheck. #​3776
  • PySet and PyFrozenSet iterators now always iterate the equivalent of iter(set). (A "fast path" with no noticeable performance benefit was removed.) #​3849
  • Move implementations of FromPyObject for &str, Cow<str>, &[u8] and Cow<[u8]> onto a temporary trait FromPyObjectBound when gil-refs feature is deactivated. #​3928
  • Deprecate GILPool, Python::with_pool, and Python::new_pool. #​3947
Removed
  • Remove all functionality deprecated in PyO3 0.19. #​3603
Fixed
  • Match PyPy 7.3.14 in removing PyPy-only symbol Py_MAX_NDIMS in favour of PyBUF_MAX_NDIM. #​3757
  • Fix segmentation fault using datetime types when an invalid datetime module is on sys.path. #​3818
  • Fix non_local_definitions lint warning triggered by many PyO3 macros. #​3901
  • Disable PyCode and PyCode_Type on PyPy: PyCode_Type is not exposed by PyPy. #​3934

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot added the dependency label Mar 26, 2024
@renovate renovate bot force-pushed the renovate/pyo3-0.x branch 4 times, most recently from 7453b83 to 485d840 Compare April 1, 2024 21:34
@renovate renovate bot changed the title Update Rust crate pyo3 to v0.21.0 Update Rust crate pyo3 to v0.21.1 Apr 1, 2024
@renovate renovate bot force-pushed the renovate/pyo3-0.x branch 4 times, most recently from d827943 to 1382fdc Compare April 16, 2024 07:05
@renovate renovate bot changed the title Update Rust crate pyo3 to v0.21.1 Update Rust crate pyo3 to v0.21.2 Apr 16, 2024
@renovate renovate bot force-pushed the renovate/pyo3-0.x branch 2 times, most recently from d9dcac9 to fc405c7 Compare April 18, 2024 07:46
@renovate renovate bot force-pushed the renovate/pyo3-0.x branch 2 times, most recently from 6daa2c5 to 45c53cb Compare May 2, 2024 07:09
@renovate renovate bot changed the title Update Rust crate pyo3 to v0.21.2 Update Rust crate pyo3 to v0.22.0 Jun 24, 2024
@renovate renovate bot changed the title Update Rust crate pyo3 to v0.22.0 Update Rust crate pyo3 to v0.22.1 Jul 7, 2024
@renovate renovate bot changed the title Update Rust crate pyo3 to v0.22.1 Update Rust crate pyo3 to v0.22.2 Jul 17, 2024
Mainly we adjust usages of the GIL refs API to `Bound<T>`.
Copy link
Contributor Author

renovate bot commented Aug 2, 2024

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

⚠️ Warning: custom changes will be lost.

This comment was marked as outdated.

Copy link

github-actions bot commented Aug 2, 2024

Benchmark for a45137c

Click to view benchmark
Test Base PR %
Reclass::inventory() multi-threaded 1625.5±64.87µs 1655.4±114.33µs +1.84%
Reclass::inventory() single-threaded 3.6±0.05ms 3.6±0.04ms 0.00%

Copy link
Member

@simu simu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested updated module with Commodore/Kapitan, everything still works fine

@simu simu merged commit 7b34c22 into main Aug 2, 2024
18 checks passed
@simu simu deleted the renovate/pyo3-0.x branch August 2, 2024 13:36
@simu simu changed the title Update Rust crate pyo3 to v0.22.2 Update pyo3 to v0.22 and update code to use pyo3 Bound types Oct 15, 2024
@simu simu removed the dependency label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant