Skip to content

chore(deps): bump pyo3 to 0.27 and simplify ffi interfaces#23

Merged
vvanglro merged 5 commits intomainfrom
update-dep
Jan 29, 2026
Merged

chore(deps): bump pyo3 to 0.27 and simplify ffi interfaces#23
vvanglro merged 5 commits intomainfrom
update-dep

Conversation

@vvanglro
Copy link
Member

Upgrade PyO3 from 0.20.1 to 0.27.2 and infer from 0.15.0 to 0.19.0. Replace legacy reference types with Bound APIs and owned handles. Accept &str directly in from_path to leverage automatic Python-to-Rust string conversion. Switch blocking calls from allow_threads to detach for explicit GIL release during file operations. Add lint configuration for PyPy-specific cfg flags.

Upgrade PyO3 from 0.20.1 to 0.27.2 and infer from 0.15.0 to 0.19.0.
Replace legacy reference types with Bound APIs and owned handles.
Accept &str directly in from_path to leverage automatic Python-to-Rust
string conversion. Switch blocking calls from allow_threads to detach
for explicit GIL release during file operations. Add lint configuration
for PyPy-specific cfg flags.
@gemini-code-assist
Copy link

Summary of Changes

Hello @vvanglro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request delivers a substantial update to the project's Python-Rust interface by upgrading key dependencies, PyO3 and infer, to their latest versions. The changes streamline the Foreign Function Interface (FFI) by adopting modern PyO3 patterns, simplifying string conversions, and refining GIL management for blocking calls. Additionally, it introduces a linting rule to improve PyPy compatibility, ensuring the project remains robust across different Python runtimes.

Highlights

  • PyO3 and Infer Crate Upgrades: The pyo3 crate has been significantly bumped from version 0.20.1 to 0.27.2, and the infer crate from 0.15.0 to 0.19.0, bringing in the latest features and improvements from these core dependencies.
  • Modernized FFI Interfaces: Legacy PyO3 reference types have been replaced with the new Bound APIs and owned handles, aligning the codebase with current best practices for Python-Rust interoperability.
  • Simplified String Handling: The from_path function now directly accepts &str for file paths, leveraging PyO3's automatic Python-to-Rust string conversion and simplifying the interface.
  • Improved GIL Management: Blocking operations in from_bytes and from_path now use _py.detach() instead of _py.allow_threads(), providing more explicit and potentially safer Global Interpreter Lock (GIL) release during file operations.
  • PyPy Compatibility Linting: A new lint configuration has been added to Cargo.toml to warn about unexpected_cfgs specifically for cfg(PyPy), enhancing compatibility and maintainability for PyPy environments.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request upgrades PyO3 and infer, and refactors the FFI interface. The changes are mostly correct, but I've found critical issues related to memory safety when using py.detach(). The provided closures capture non-'static references, which can lead to use-after-free errors. I've suggested fixes that involve copying data to ensure it has a 'static lifetime. Additionally, there's a small issue with a build dependency version in Cargo.toml that should be updated.

Update pyo3-build-config to 0.27.2 and use owned types within
detached closures to ensure data persists across thread boundaries.
This fixes lifetime errors where references were being passed into
closures that might outlive their scope.
@vvanglro vvanglro merged commit 620b560 into main Jan 29, 2026
16 checks passed
@vvanglro vvanglro deleted the update-dep branch January 29, 2026 08:58
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

Successfully merging this pull request may close these issues.

1 participant