Skip to content

Pyerr isinstance#3826

Merged
davidhewitt merged 3 commits intoPyO3:mainfrom
LilyFirefly:pyerr-isinstance
Feb 12, 2024
Merged

Pyerr isinstance#3826
davidhewitt merged 3 commits intoPyO3:mainfrom
LilyFirefly:pyerr-isinstance

Conversation

@LilyFirefly
Copy link
Contributor

@LilyFirefly LilyFirefly commented Feb 11, 2024

Implements more of the Bound api from #3684.

@codspeed-hq
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%

@LilyFirefly LilyFirefly 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
)]
#[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...)

LilyFirefly 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
@LilyFirefly LilyFirefly 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.

2 participants