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 rule caching is buggy #364

Closed
LilithHafner opened this issue Sep 20, 2023 · 0 comments · Fixed by #365
Closed

pyconvert rule caching is buggy #364

LilithHafner opened this issue Sep 20, 2023 · 0 comments · Fixed by #365
Labels
bug Something isn't working

Comments

@LilithHafner
Copy link
Contributor

Affects: PythonCall

Describe the bug
When I add a new conversion rule, it only applies when converting to Julia types T that have never had pyconvert(T, x) called on them.

julia> pyexec("""
       class Hello:
           pass
       """, Main)

julia> x = pyeval("Hello()", Main)
Python: <Hello object at 0x14759a210>

julia> pyconvert(Any, x)
Python: <Hello object at 0x14759a210>

julia> t = pytype(x)
Python: <class 'Hello'>

julia> PythonCall.pyconvert_add_rule(pyconvert(Any, t.__module__)*":"*pyconvert(Any, t.__qualname__), String, (_, _) -> "Hello!!") 

julia> pyconvert(Any, x)
Python: <Hello object at 0x14759a210> ### BUG ### <===========================================

julia> pyconvert(String, x)
"Hello!!"

julia> empty!.(values(PythonCall.PYCONVERT_RULES_CACHE)) ### A possible fix ###
2-element Vector{Dict{Ptr{PythonCall.C.PyObject}, Vector{Function}}}:
 Dict()
 Dict()

julia> pyconvert(Any, x)
"Hello!!"

Your system
PythonCall v0.9.14

Possible fix
Make pyconvert_add_rule clear the rule cache

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
1 participant