Skip to content

builtins/eval throws 'frame does not exist' #244

Open

Description

@behrica
(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

Activity

  1. jjtolton commented on Jul 6, 2023

    @jjtolton
    Contributor

    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.
  2. jjtolton commented on Oct 26, 2023

    @jjtolton
    Contributor

    @behrica

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

    Black magic.

    Actually...

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

    also works 🤔

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

    (python/eval "eval('eval(\"1\")', {\"eval\": eval})" {"eval" python/eval}) ;;=> 1
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions