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

fix native types not implementing is_type_of correctly #4981

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

davidhewitt
Copy link
Member

I noticed this while having a look at removing all the _bound methods from the code (as a first step towards 0.25).

This seems like a bugfix worth landing on the 0.24 series, so I split it out.

Copy link

codspeed-hq bot commented Mar 14, 2025

CodSpeed Performance Report

Merging #4981 will improve performances by 11.99%

Comparing davidhewitt:is-type-of (1535c42) with main (fdf62e0)

Summary

⚡ 1 improvements
✅ 86 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
not_a_list_via_extract 2 µs 1.8 µs +11.99%

@@ -152,7 +152,7 @@ macro_rules! pyobject_native_type_info(

$(
#[inline]
fn is_type_of_bound(obj: &$crate::Bound<'_, $crate::PyAny>) -> bool {
fn is_type_of(obj: &$crate::Bound<'_, $crate::PyAny>) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

The point here being that is_type_of_bound is defaulted to just call is_type_of. is_type_of has a generic default which calls PyObject_TypeCheck instead of more specific (faster) functions like PyList_Check.

@davidhewitt
Copy link
Member Author

Performance improvement is likely real due to fixing use of specialised functions. Nice free win 🎉

@Icxolu Icxolu added this pull request to the merge queue Mar 17, 2025
Merged via the queue into PyO3:main with commit 8e7ac5d Mar 17, 2025
48 checks passed
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.

2 participants