Closed Felecarpp closed 2 years ago
Testing if the function is a method type would fix the error.
def set_handler(name: str, func) -> None:
if name not in event_registry:
event_registry[name] = set()
if isinstance(func, types.MethodType):
event_registry[name].add(_WeakMethod(func, _make_callback(name)))
else:
event_registry[name].add(_ref(func, _make_callback(name)))
or
def set_handler(name: str, func) -> None:
if name not in event_registry:
event_registry[name] = set()
if inspect.ismethod(func):
event_registry[name].add(_WeakMethod(func, _make_callback(name)))
else:
event_registry[name].add(_ref(func, _make_callback(name)))
I don't know which is better.
Thanks for opening the ticket, and thanks for the suggestions j-fdion. I'll push out a fix shortly.
Looks like isinstance
is about 45% faster, so lets go with that.
New 2.1 release was pushed out with the bugfix. Thanks!
Hey ! Thanks for this greet library ! In the README.rst I can read:
That works fine with methods but with functions I get this error: