You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works as expected until on the python side I call the function with an integer that has value.bit_length() > 31, so for example foo = test_variant_with_int(9223372036854775808). In that case the value cannot be cast to int because of the overflow so instead it is implicitely casted to bool.
Note that when binding a C++ function that looks like auto bar(int value), calling the function on python side with an int that has value.bit_length() > 31 throws a TypeError just as expected.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello there !
I'm currently trying to wrap a function that looks like this :
This works as expected until on the python side I call the function with an integer that has
value.bit_length() > 31
, so for examplefoo = test_variant_with_int(9223372036854775808)
. In that case the value cannot be cast toint
because of the overflow so instead it is implicitely casted tobool
.I'd have expected a
TypeError
, like what I'd get if I passed a string or anything else. Looking at https://github.com/pybind/pybind11/blob/master/include/pybind11/stl.h#L323 there is aconvert
parameter that seems to disable implicit casts. Is there a way to control this from the client code ?[Edit]
Note that when binding a C++ function that looks like
auto bar(int value)
, calling the function on python side with an int that hasvalue.bit_length() > 31
throws aTypeError
just as expected.Beta Was this translation helpful? Give feedback.
All reactions