libpython-clj icon indicating copy to clipboard operation
libpython-clj copied to clipboard

builtins/eval throws 'frame does not exist'

Open behrica opened this issue 2 years ago • 2 comments

(require-python '[builtins :as bt])
(bt/eval "1") 
;Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:708) .
; SystemError: frame does not exist

while this works

(require-python '[builtins :as bt])
(bt/eval "1" {})

while in python both work:

>>> eval('1+1')
2
>>> eval('1+1',{})
2

behrica avatar Jul 06 '23 20:07 behrica

If you try from embedded mode it should work. I can't remember the trick but you need to create a base frame by running py/run-simple-string otherwise.

Footnotes:

  1. if you do (import-python) you get access to the Python namespace which will Let you do python/eval.

jjtolton avatar Jul 06 '23 21:07 jjtolton

@behrica

(import-python)
(python/eval "1" (:globals (py/run-simple-string ""))) ;;=> 1

Black magic.

Actually...

(python/eval "1" (python/dict)) ;;=> 1

also works :thinking:

You know, I gotta say, sometimes libpython-clj confuses me.

(python/eval "eval('eval(\"1\")', {\"eval\": eval})" {"eval" python/eval}) ;;=> 1

jjtolton avatar Oct 26 '23 03:10 jjtolton