python-eel / Eel

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

Why does Eel have the function _expose protected? #679

Open nricciardi opened 1 year ago

nricciardi commented 1 year ago

Hi (I'm new), my question is why does Eel have the function _expose protected?

It is a very handy feature in case you want to expose methods instead of function in case there are multiple classes having the same methods (very likely in the case of inheritance)... now you have to do this:

import eel

class MyClass:
   def my_method(self):
      pass

my_class = MyClass()
eel._expose("other_name", my_class.my_method)

Couldn't you add an alias parameter to .expose(...)?

ChrisKnott commented 1 year ago

I don't think this was a deliberate design decision, I just initially only thought of using it as a decorator. _expose() is just an implementation detail that I didn't realise you could use like this.

I don't think there's anything wrong with it, and it could be made part of the public API but I would personally wrap my_class.my_method in a function.