Skip to content

allow from_py_with on function args to take a fn(&Bound) -> PyResult#3837

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:from-py-with-pyfunction
Feb 14, 2024
Merged

allow from_py_with on function args to take a fn(&Bound) -> PyResult#3837
davidhewitt merged 1 commit intoPyO3:mainfrom
Icxolu:from-py-with-pyfunction

Conversation

@Icxolu
Copy link
Member

@Icxolu Icxolu commented Feb 14, 2024

Part of #3684

This allows the #[pyfunction] and #[pymethod] arguments to use Bound API extractors in #[pyo3(from_py_with = ...)]. I reused the internal Extractor implementation that I recently introduced in #3828. For now I left it where I added it initially, but if we like to move it to a different place or module, I can do that.

There is still a lot of old APIs surrounding this, but it might be better to tackle them separately.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 14, 2024

CodSpeed Performance Report

Merging #3837 will degrade performances by 15.63%

Comparing Icxolu:from-py-with-pyfunction (1a4a44d) with main (0c12d91)

Summary

⚡ 1 improvements
❌ 3 regressions
✅ 75 untouched benchmarks

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

Benchmarks breakdown

Benchmark main Icxolu:from-py-with-pyfunction Change
mapping_from_dict 300 ns 355.6 ns -15.63%
f64_from_pyobject 461.1 ns 405.6 ns +13.7%
sequence_from_list 327.8 ns 383.3 ns -14.49%
sequence_from_tuple 232.8 ns 260.6 ns -10.66%

Copy link
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.

Thanks, that was straightforward!

There is still a lot of old APIs surrounding this, but it might be better to tackle them separately.

If you mean the rest of extract_argument, I've got pretty much all of it in #3708. That's just blocked on #3802 and then I think it's finally mergeable. I'll try to update #3802 tonight, if my toddler ever settles down for bed... 🙃

@@ -20,7 +20,7 @@ impl<'a, T> From<fn(&'a PyAny) -> PyResult<T>> for Extractor<'a, '_, T> {
}

impl<'a, 'py, T> Extractor<'a, 'py, T> {
Copy link
Member

Choose a reason for hiding this comment

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

Given that Extractor should be just temporary code which we'll remove again when the GIL Ref API is dead and gone, I'm fine with leaving it here for now 👍

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Feb 14, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Feb 14, 2024
Merged via the queue into PyO3:main with commit 9902633 Feb 14, 2024
@Icxolu Icxolu deleted the from-py-with-pyfunction branch February 14, 2024 22:48
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