-
Notifications
You must be signed in to change notification settings - Fork 633
fix typing in add_listener and remove_listener #1335
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Use the union to typecheck these functions
Codecov Report
@@ Coverage Diff @@
## develop #1335 +/- ##
===========================================
+ Coverage 65.92% 65.99% +0.06%
===========================================
Files 86 86
Lines 8955 8958 +3
===========================================
+ Hits 5904 5912 +8
+ Misses 3051 3046 -5 |
Declaration of Line 45 in c7ba84a
|
Thank you. Since the notifier accepts coroutines, could you also add the Awaitable in the MessageRecipient definition? MessageRecipient = Union[Listener, Callable[[Message], Union[Awaitable[None], None]]] Then we can also remove the cast in def _on_message_received(self, msg: Message) -> None:
for callback in self.listeners:
res = cast(Union[None, Optional[Awaitable[Any]]], callback(msg))
if res is not None and self._loop is not None and asyncio.iscoroutine(res):
# Schedule coroutine
self._loop.create_task(res) |
Done :) |
Pylint complains about unused imports now. I will merge once that's fixed. |
Aha, I see. Will fix it. Still learning how to contribute. Also for the if statement in def _on_message_received(self, msg: Message) -> None:
for callback in self.listeners:
res = callback(msg)
if res is not None and self._loop is not None and asyncio.iscoroutine(res):
# Schedule coroutine
self._loop.create_task(res) def _on_message_received(self, msg: Message) -> None:
for callback in self.listeners:
if (res := callback(msg)) is not None and self._loop is not None and asyncio.iscoroutine(res):
# Schedule coroutine
self._loop.create_task(res) |
The walrus operator would fail in python 3.7 |
Use the union to typecheck these functions