Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyconvert_add_rule must be executed before using pyimport in __init__() #500

Closed
laggvar opened this issue May 16, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@laggvar
Copy link

laggvar commented May 16, 2024

Affects: PythonCall

Description:

It took me ages to figure out why the following did not manage to add a conversion rule, despite it following the documentation here and here

const mylib = pynew()
function __init__()
    pycopy!(mylib, pyimport("mylib")
    pyconvert_add_rule(".......", T, _func)
end

It seems swapping the order solves the issue

const mylib = pynew()
function __init__()
    pyconvert_add_rule(".......", T, _func)
    pycopy!(mylib, pyimport("mylib")
end

i.e. the conversion rule must be added before pyimport is called. I guess it is too late to add the rules once the python executable has started? Perhaps this should be clarified in the documentation?

@laggvar laggvar added the bug Something isn't working label May 16, 2024
@cjdoris
Copy link
Collaborator

cjdoris commented May 20, 2024

No that's a bug, you should be able to add rules at any point. What version of PythonCall are you on? Please post some complete reproducing code which demonstrates the issue.

@laggvar
Copy link
Author

laggvar commented Sep 10, 2024

I am certain I verified the bug multiple times before filing the bug report, but I cannot reproduce the issue, unfortunately.

@laggvar laggvar closed this as completed Sep 10, 2024
@cjdoris
Copy link
Collaborator

cjdoris commented Sep 10, 2024

Thanks for closing. I have some vague recollection that we fixed a bug a while back to do with cacheing these conversion rules - maybe that fixed your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants