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

Add an API isinstance(inst, cls) that mirrors the Python isinstance. #805

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

hawkinsp
Copy link
Contributor

@hawkinsp hawkinsp commented Dec 2, 2024

The current isinstance<T>(inst) tests if a Python object is an instance of a bound C++ class. This new overload tests if a Python object is an instance of a Python class. I have needed this helper in several nanobind-using codebases, and the same API exists in pybind11.

include/nanobind/nb_misc.h Outdated Show resolved Hide resolved
@wjakob
Copy link
Owner

wjakob commented Dec 4, 2024

This looks great. Could I ask you to add a changelog entry?

The current `isinstance<T>(inst)` tests if a Python object is an
instance of a bound C++ class. This new overload tests if a Python
object is an instance of a Python class. I have needed this helper in
several nanobind-using codebases, and the same API exists in pybind11.
@hawkinsp
Copy link
Contributor Author

hawkinsp commented Dec 4, 2024

This looks great. Could I ask you to add a changelog entry?

Done!

@wjakob
Copy link
Owner

wjakob commented Dec 5, 2024

Thanks!

@wjakob wjakob merged commit ddc7ad5 into wjakob:master Dec 5, 2024
30 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