Skip to content

Commit 3762868

Browse files
committed
Fix add_event raising AttributeError.
1 parent 492a3ec commit 3762868

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

twitchio/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ async def wrapped(func):
198198
future.set_result(args)
199199

200200
def add_event(self, callback: Callable, name: str = None) -> None:
201-
if not inspect.iscoroutine(callback) and not inspect.iscoroutinefunction(callback.func):
202-
raise ValueError("callback must be a coroutine")
201+
try:
202+
func = callback.func
203+
except AttributeError:
204+
func = callback
205+
206+
if not inspect.iscoroutine(func) and not inspect.iscoroutinefunction(func):
207+
raise ValueError("Event callback must be a coroutine")
203208

204209
event_name = name or callback.__name__
205210
callback._event = event_name # used to remove the event
@@ -212,7 +217,7 @@ def add_event(self, callback: Callable, name: str = None) -> None:
212217

213218
def remove_event(self, callback: Callable) -> bool:
214219
if not hasattr(callback, "_event"):
215-
raise ValueError("callback is not a registered event")
220+
raise ValueError("Event callback is not a registered event")
216221

217222
if callback in self._events[callback._event]:
218223
self._events[callback._event].remove(callback)

0 commit comments

Comments
 (0)