Giter VIP home page Giter VIP logo

Comments (4)

hoodmane avatar hoodmane commented on June 12, 2024

Does this work?

const enumValue = pyodide.runPython(`
   from pyodide.ffi import create_proxy
   create_proxy(Foo.bar)
`);

from pyodide.

seanpk avatar seanpk commented on June 12, 2024

Unfortunately, no; it is still coming out as an integer. :-(

Looking closer at the library I'm calling, they have implemented a enum.IntEnum, which should be convertible to and from an integer value, and so I'm pretty sure the default behavior of pyodide would be OK. However, in the function I'm calling they're doing an isinstance test so I still need the actual enum object to make it work.

That said, I have found a workaround I think is OK:

const locals = {
  the_magic_object: pyproxyObjectThatTookALotOfWorkToCreate,
  the_enum_int_value: functionThatFiguresOutTheRightValue(),
  ...allTheOtherVarialblesNeededToCallTheFunction
}
const script = `
  from bar import foo
  foo_enum = Foo(the_enum_int_value)
  the_magic_object.magic_function(foo_enum, ...)
`
pyodide.runPython(script, { locals })

It still may be worthwhile being able to disable translations at times, but I'm not blocked until that is decided and figured out.

Thanks!

from pyodide.

hoodmane avatar hoodmane commented on June 12, 2024

Seems to work for me.

const v = pyodide.runPython(`
   from pyodide.ffi import create_proxy
   from enum import Enum
   class A(Enum):
      v = 1

create_proxy(A.v, roundtrip=False)
`);
const  f = pyodide.runPython(`
   def f(x):
      print("x is A.v?", x is A.v)
   f
`);

f(v)

Prints x is A.v? True

from pyodide.

seanpk avatar seanpk commented on June 12, 2024

I'll have to try again with the roundtrip=False option.

from pyodide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.