Skip to content

port Python::run to Bound API#3816

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:python-run
Feb 9, 2024
Merged

port Python::run to Bound API#3816
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:python-run

Conversation

@Icxolu
Copy link
Copy Markdown
Member

@Icxolu Icxolu commented Feb 9, 2024

Part of #3684, split from #3716 and followup to #3806

This converts to the Python::run function to the new API. For easier reviewing this focuses purely on run/run_bound and leaves the PyDict methods for followup PRs.

This also changes the py_run macro in a way, which allows it to consume both (gil-ref and Bound) APIs. So there is no need to introduce a py_run_bound.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Feb 9, 2024
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thank you, this is so much more elegant than my very crude and churn-heavy py_run_bound!

I guess this basically makes the rest of #3716 ready to throw away that this point? It's now got substantial diff which will never be merged.

use ::std::option::Option::*;
if let ::std::result::Result::Err(e) = $py.run($code, None, Some($dict)) {
use $crate::PyNativeType;
if let ::std::result::Result::Err(e) = $py.run_bound($code, None, Some(&$dict.as_borrowed())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haha using .as_borrowed() here is an incredibly effective way to get it to compile either way around 😂

($py:expr, *$dict:expr, $code:expr) => {{
use ::std::option::Option::*;
if let ::std::result::Result::Err(e) = $py.run($code, None, Some($dict)) {
use $crate::PyNativeType;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a little surprised that this doesn't need an #[allow(unused_imports)] 🤔. Eh, we can add it later if it becomes a problem.

@davidhewitt davidhewitt added this pull request to the merge queue Feb 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Feb 9, 2024
@Icxolu
Copy link
Copy Markdown
Member Author

Icxolu commented Feb 9, 2024

Fixed the conflict

I guess this basically makes the rest of #3716 ready to throw away that this point? It's now got substantial diff which will never be merged.

If you prefer to close that one and merge the PyDict changes in a different PR (or multiple if needed) I can continue with that and prepare them.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 9, 2024

CodSpeed Performance Report

Merging #3816 will degrade performances by 11.36%

Comparing Icxolu:python-run (4d423b0) with main (b7fb9e6)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 77 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main Icxolu:python-run Change
list_via_extract 392.2 ns 336.7 ns +16.5%
not_a_list_via_downcast 216.7 ns 244.4 ns -11.36%

@davidhewitt davidhewitt added this pull request to the merge queue Feb 9, 2024
@davidhewitt
Copy link
Copy Markdown
Member

If you prefer to close that one and merge the PyDict changes in a different PR (or multiple if needed) I can continue with that and prepare them.

👍 let's do that, thank you for taking that one over and doing a much better job of it than I did!

Merged via the queue into PyO3:main with commit 45f2b0a Feb 9, 2024
@Icxolu Icxolu deleted the python-run branch February 9, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants