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

Pyerr isinstance #3826

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Pyerr isinstance #3826

merged 3 commits into from
Feb 12, 2024

Conversation

LilyFoote
Copy link
Contributor

@LilyFoote LilyFoote commented Feb 11, 2024

Implements more of the Bound api from #3684.

Copy link

codspeed-hq bot commented Feb 11, 2024

CodSpeed Performance Report

Merging #3826 will degrade performances by 11.36%

Comparing LilyFoote:pyerr-isinstance (1d52ce4) with main (baf5c8e)

Summary

⚡ 2 improvements
❌ 1 regressions
✅ 76 untouched benchmarks

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

Benchmarks breakdown

Benchmark main LilyFoote:pyerr-isinstance Change
list_via_downcast 185 ns 157.2 ns +17.67%
not_a_list_via_downcast 272.2 ns 216.7 ns +25.64%
f64_from_pyobject 433.3 ns 488.9 ns -11.36%

@LilyFoote LilyFoote marked this pull request as ready for review February 11, 2024 23:03
@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Feb 11, 2024
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 again! Got a few suggestions for this one...

src/err/mod.rs Outdated Show resolved Hide resolved
src/err/mod.rs Outdated Show resolved Hide resolved
src/err/mod.rs Outdated
#[inline]
pub fn is_instance(&self, py: Python<'_>, ty: &PyAny) -> bool {
self.is_instance_bound(py, ty.into_py(py).into_bound(py))
Copy link
Member

Choose a reason for hiding this comment

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

With &Bound for the argument, this should work:

Suggested change
self.is_instance_bound(py, ty.into_py(py).into_bound(py))
self.is_instance_bound(py, &ty.as_borrowed())

Potentially are you willing to open a PR to recommend using as_borrowed() as the way to go from &PyAny to &Bound in the migration guide? e.g.

let gil_ref: &PyAny = ...;
let bound: &Bound<PyAny> = &gil_ref.as_borrowed();

(hopefully most user code won't need to care about this because all of it will just get migrated over, but this might still be useful for users to be aware as they rewrite their code...)

LilyFoote and others added 2 commits February 11, 2024 23:22
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
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.

Perfect, thanks again!

@davidhewitt davidhewitt added this pull request to the merge queue Feb 12, 2024
Merged via the queue into PyO3:main with commit 1279467 Feb 12, 2024
35 of 38 checks passed
@LilyFoote LilyFoote deleted the pyerr-isinstance branch February 12, 2024 10:15
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.

None yet

2 participants