Replies: 2 comments 4 replies
-
This is also a question of performance. Checking that the argument is exactly of type |
Beta Was this translation helpful? Give feedback.
2 replies
-
Python itself does a whole lot of is-this-an-int checks (which do allow subclasses), so they're optimized with a bit in the type flags:
Not so much worse than a pointer comparison. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If you bind this function:
what sort of Python objects should you be able to pass to
example()
?I noticed today that nanobind and pybind11 have different opinions on this. nanobind will only accept exactly a Python int; even subclasses of int don't qualify. pybind11 accepts subclasses of int, as well as non-int objects that define
__index__
; but a non-int object that only defines__int__
requires a conversion.I'm dubious about the wisdom of allowing a call to
__index__
to not count as a conversion, because e.g. nanobind enums define__index__
and I'm not sure they should be accepted if someone wants an int without conversion. But subtypes of int seem pretty safe to me. I'm curious what others' opinions on this are.Beta Was this translation helpful? Give feedback.
All reactions