JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
720 stars 61 forks source link

Passing functions to Julia as global variables is buggy #394

Closed LilithHafner closed 8 months ago

LilithHafner commented 8 months ago

Affects: JuliaCall

Describe the bug Passing functions to Julia as global variables is buggy

>>> from juliacall import Main
>>> Main.x = 5
>>> Main.x # Fine
5
>>> def f(y):
...     return y + 1
... 
>>> Main.f = f
>>> Main.f # Bad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/x/.julia/packages/PythonCall/qTEA1/src/jlwrap/any.jl", line 195, in __getattr__
    return self._jl_callmethod($(pyjl_methodnum(pyjlany_getattr)), k)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in method _jl_callmethod of ModuleValue object at 0x103dc7a00> returned NULL without setting an exception
>>> Main.z = 7
>>> Main.z
7
>>> Main.f  # Very bad
7
>>> Main.x
5
cjdoris commented 8 months ago

Thanks - fixed on 'main'.