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

PyO3: Upgrade to v0.23.x #21671

Open
1 of 4 tasks
tdyas opened this issue Nov 19, 2024 · 0 comments
Open
1 of 4 tasks

PyO3: Upgrade to v0.23.x #21671

tdyas opened this issue Nov 19, 2024 · 0 comments
Assignees

Comments

@tdyas
Copy link
Contributor

tdyas commented Nov 19, 2024

Upgrade to the latest PyO3 v0.23.x release from v.0.22.x.

Migration steps:

  • Switch pyclass-annotated types to use explicit GIL synchronization via GILProtected since implicit GIL sync goes away in v.0.23.x. use GILProtected to synchronize access to various pyclass types #21670
  • Upgrade to v0.23.x (but work around deprecation of ToPyObject and IntoPy traits). PyO3: upgrade to v0.23.x #21657
  • Migrate to IntoPyObject trait from ToPyObject and IntoPy traits, reenable deprecation warnings in the affected files.
  • Rename Pants functions with _bound in the name to no longer have _bound in the name. (The functions were renamed as part of the PyO3 v0.22.x migration, but can now be renamed back to the original names, just like PyO3 did in v0.23.x.)
@tdyas tdyas self-assigned this Nov 19, 2024
tdyas added a commit that referenced this issue Nov 19, 2024
…21670)

As part of [upgrading to PyO3
v0.23.x](#21671), access
to`pyclass`-annotated types will no longer be implicitly synchronized
against the Python GIL. Those `pyclass`-annotated types [must now be
`Sync`](https://pyo3.rs/v0.23.1/class/thread-safety) and provide that
synchronization explicitly.

Several places in Pants use `RefCell` which is not Send/Sync by itself.
This PR uses `pyo3::sync::GILProtected` to provide explicit
synchronization against the GIL for those use cases. (Eventually, we may
wish to not use `GILProtected` to enable use of the Python 3.13 "no GIL"
free threaded build, but that day is not today.)

[Migration
guide](https://pyo3.rs/v0.23.1/migration.html#free-threaded-python-support)
tdyas added a commit that referenced this issue Nov 21, 2024
[Upgrade to v0.23.x of the `pyo3`
crate](#21671):

- Functions in PyO3 with `_bound` suffixes existed in PyO3 only for
easing migration to the `Bound` API. They are deprecated now and new
methods without the `_bound` suffixes have been re-introduced in PyO3.
This PR renames call sites accordingly and updates code to also reflect
that some of the new APIs (e.g., `PyTuple::new`) are now fallible.

- The `IntoPy` and `ToPyObject` traits are deprecated in favor of the
new `IntoPyObject` trait (which is fallible). To ease migration, this PR
only disables deprecation warnings as errors in the affected files.
(Unfortunately, `IntoPyObject` was not introduced in the current v0.22.x
version and so we cannot migrate ahead of the upgrade (unlike what was
done in #21670 for the new
`pyclass` Sync requirement).) Migration will take place in follow-on
PRs.
 
- This PR does add an implementation of `IntoPyObject` for `&Value` to
support some existing call sites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant