Replies: 1 comment 1 reply
-
Well... it's a bug apparently (see issue #786). |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I currently use pybind11 to create Python bindings for my library and it's all working as I want. However, I would like to switch to nanobind and I am facing some problems when it comes to binding various class factory constructors.
Using pybind11, I have something like this:
Using nanobind, I have converted the above to:
However, when I run my Python tests, I get the following error for my
SedDocument
class:And, for my
SolverForwardEuler
class, I get:Regarding my
SedDocument
class, the factory class factory constructor has the following signature:where
SedDocumentPtr
isstd::shared_ptr<SedDocument>
(and something similar forFilePtr
). Otherwise, yes, the argument is optional, hence I would like to be able to call it from Python using eitherdocument = oc.SedDocument()
,document = oc.SedDocument(file)
(wherefile
is someFilePtr
object) or evendocument = oc.SedDocument(None)
. The last two calls are possible, but not the first one.For my
SolverForwardEuler
class, I have:where
SolverForwardEulerPtr
isstd::shared_ptr<SolverForwardEuler>
. So, from Python, I would just like to be able to callsolver = oc.SolverForwardEuler()
, but this is simply not working.I have tried various things, but the only thing that has worked so far is to use
def_static()
, but I clearly don't want my users to do something likedocument = oc.SedDocument.create()
orsolver = oc.SolverForwardEuler.create()
.Regarding my
SedDocument
class's factory constructor, I get the feeling (from https://nanobind.readthedocs.io/en/latest/porting.html#none-null-arguments) that I might not be able to have an optional parameter with a default of value ofNone
in Python? So, my binding code above might just be ineffective? Still, I have tried with:but then I get the following error when running my Python tests:
I would imagine that what I want to do is very "basic", so it must be possible using nanobind, not least since https://nanobind.readthedocs.io/en/latest/api_core.html#_CPPv4I0EN8nanobind4new_E illustrates exactly what I am after (minus the optional parameter).
So, what am I missing?...
Beta Was this translation helpful? Give feedback.
All reactions