Registering rule for converting from custom Python class with __iter__ method #570
Unanswered
wilf-phasecraft
asked this question in
Q&A
Replies: 1 comment
-
The solution seems to be bumping the priority to
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The 'Conversion to Julia' page of the docs provides some information on how to implement custom conversion rules. At the top of this page it states
But doesn't say much in the way of how this is done. At the bottom of the same page, there is documentation for the
PythonCall.Convert.pyconvert_add_rule
function, which is enables one to register a custom conversion rule on the Julia side. My assumption is that these conversion rules are what determined the type that gets passed to a Julia function called from Python.Unfortunately I haven't been able to get JuliaCall to recognise these custom conversion methods when the Python class implements an
__iter__
method. I'm able to manually convert the Python object to a Julia type and then pass that to the Julia function, but for convenience it would be ideal if this could happen automatically, like it does for canonical types. I'm not sure where I'm going wrong, or if there's more documentation/examples available for this.Some more info:
I have a custom type, which has a defined Julia
struct
and a defined Pythonclass
, each with identical fields. In my Julia package I have defined several a method with the following call signature and defined a module__init__
method that attempts to register this with PythonCall.On the Python side I then have
and
But unfortunately I get the standard Julia
MethodError
However, if I remove the
__iter__
method then it converts without problem. I have also tried defining the conversion method aswithout success.
Beta Was this translation helpful? Give feedback.
All reactions