-
-
Notifications
You must be signed in to change notification settings - Fork 776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to prevent default type translations #4689
Comments
Does this work? const enumValue = pyodide.runPython(`
from pyodide.ffi import create_proxy
create_proxy(Foo.bar)
`); |
Unfortunately, no; it is still coming out as an integer. :-( Looking closer at the library I'm calling, they have implemented a 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! |
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 |
I'll have to try again with the |
馃殌 Feature
Add an option to
runPython
(and related functions) to NOT translate values back to JavaScript, but instead provide aPyProxy
object.Motivation
Some Python libraries make types based on
enum
and expect them as parameters. They do not accept the integer3
when calling a function, but require thatFoo.bar
be provide.Pitch
To solve this, I would like to be able to use
runPython
for a special case that doesn't do the type translation, e.g.:Alternatives
Without this feature, I don't see how to call the function without moving (nearly) the whole algorithm into a
runPython
call.The text was updated successfully, but these errors were encountered: