python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.28k stars 581 forks source link

AssertionError: Already exposed function with name "test" #688

Open nricciardi opened 1 year ago

nricciardi commented 1 year ago

Hi, I'm trying to expose the method test of class Test using eel._expose(test, 'foo'), but I have an error: AssertionError: Already exposed function with name "test"

How to fix it?

doug-benn commented 1 year ago

Hello,

I'm struggling to reproduce the issue

Does using @eel.expose work?

Can you share some more information if you are still facing the issue?

Thanks

nricciardi commented 1 year ago

Thanks for interesting.

I can't use @eel.expose because it doesn't allow me to use alias.

Anyway, I have a class Test which accepts an object obj as parameter to be initialized, it has a method test where uses obj.

class Test:
    def __init__(self, obj):
        self.obj = obj

    def test(self):
        a = self.obj.a + "!!!"

        return a

test = Test(obj)
eel._expose(test.test, "foo")

Then I would expose a new method with the same name (foo).

doug-benn commented 1 year ago

I don't get your error it just doesn't work. As per #679 Couldn't you wrap it in a function?

class Test:
    def __init__(self, obj):
        self.obj = obj

    def test(self):
        a = self.obj.a + "!!!"

        return a

test = Test(obj)

@eel.expose
def call_test():
    data = test.test()
    print(data)

This seems to work and I don't see a problem with it - not the nicest way of doing it but

nricciardi commented 1 year ago

Thanks for answering me, but I change the test reference after first assignment, this is the problem in my point of view.