Converting a PyObject to a Julia struct

I wouldn’t use pyfunction at all here. If you just do py_add_age = add_age!, then the default argument conversion should do what you want.

Otherwise you’d have to define a convert function, of the form:

function Base.convert(::Type{Person}, o::PyObject)
    PyCall.is_pyjlwrap(o) || throw(ArgumentError("not a wrapped Julia object"))
    return PyCall.unsafe_pyjlwrap_to_objref(o)::Person
end
2 Likes