Skip to content

fix native types not implementing is_type_of correctly#4981

Merged
Icxolu merged 1 commit intoPyO3:mainfrom
davidhewitt:is-type-of
Mar 17, 2025
Merged

fix native types not implementing is_type_of correctly#4981
Icxolu merged 1 commit intoPyO3:mainfrom
davidhewitt:is-type-of

Conversation

@davidhewitt
Copy link
Copy Markdown
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.

@codspeed-hq
Copy link
Copy Markdown

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%

Comment thread src/types/mod.rs
$(
#[inline]
fn is_type_of_bound(obj: &$crate::Bound<'_, $crate::PyAny>) -> bool {
fn is_type_of(obj: &$crate::Bound<'_, $crate::PyAny>) -> bool {
Copy link
Copy Markdown
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
Copy Markdown
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