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
importthingx, y=thing.IntWrapper(1), 1print(f"cast IntWrapper to value: {x} -> {thing.cast_to_value(x)}")
print(f"cast IntWrapper to ptr: {x} -> {thing.cast_to_ptr(x)}")
print(f"cast int to value: {y} -> {thing.cast_to_value(y)}")
print(f"cast int to ptr: {y} -> {thing.cast_to_ptr(y)}")
Results in this:
cast IntWrapper to value: <thing.IntWrapper object at 0x104fad8f0> -> <thing.IntWrapper object at 0x104faf450>
cast IntWrapper to ptr: <thing.IntWrapper object at 0x104fad8f0> -> <thing.IntWrapper object at 0x104fad8f0>
cast int to value: 1 -> <thing.IntWrapper object at 0x104faf450>
Traceback (most recent call last):
File ".../test.py", line 7, in <module>
print(f"cast int to ptr: {y} -> {thing.cast_to_ptr(y)}")
~~~~~~~~~~~~~~~~~^^^
RuntimeError: std::bad_cast
cast IntWrapper to value: <thing.IntWrapper object at 0x10533ff70> -> <thing.IntWrapper object at 0x104d684f0>
cast IntWrapper to ptr: <thing.IntWrapper object at 0x10533ff70> -> <thing.IntWrapper object at 0x10533ff70>
cast int to value: 1 -> <thing.IntWrapper object at 0x10533fef0>
cast int to ptr: 1 -> <thing.IntWrapper object at 0x104d684f0>
I suppose since you are create a new object, ownership is more ambiguous if you return a pointer, but I don't think that is unique to implicit casting, and pybind11 seems to handle the issue fine? Is there some reason why nanobind can't handle this case? I'm not sure this is necessarily a bug, so I didn't post it under issues. But it should probably be mentioned in the porting guide section of the docs, if it's not fixable.
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
Uh oh!
There was an error while loading. Please reload this page.
-
It seems you aren't able to implicitly cast types from a source type to a pointer of the target type:
Running the following test:
Results in this:
While an equivalent setup in pybind11:
seems to work fine:
I suppose since you are create a new object, ownership is more ambiguous if you return a pointer, but I don't think that is unique to implicit casting, and pybind11 seems to handle the issue fine? Is there some reason why nanobind can't handle this case? I'm not sure this is necessarily a bug, so I didn't post it under issues. But it should probably be mentioned in the porting guide section of the docs, if it's not fixable.
Beta Was this translation helpful? Give feedback.
All reactions