Closed
Description
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