Skip to content

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

Closed

Description

@johroj

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?

Activity

  1. cjdoris commented on May 20, 2024

    @cjdoris
    Member

    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.

  2. johroj commented on Sep 10, 2024

    @johroj
    Author

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

  3. cjdoris commented on Sep 10, 2024

    @cjdoris
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions