diff --git a/mmpy_bot/function.py b/mmpy_bot/function.py index 1149d526..737754ef 100644 --- a/mmpy_bot/function.py +++ b/mmpy_bot/function.py @@ -6,6 +6,7 @@ import re import shlex from abc import ABC, abstractmethod +from itertools import islice from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union import click @@ -85,15 +86,11 @@ def __init__( self.needs_mention = needs_mention self.silence_fail_msg = silence_fail_msg - if allowed_users is None: - self.allowed_users = [] - else: - self.allowed_users = [user.lower() for user in allowed_users] + self.allowed_users = [user.lower() for user in (allowed_users or [])] - if allowed_channels is None: - self.allowed_channels = [] - else: - self.allowed_channels = [channel.lower() for channel in allowed_channels] + self.allowed_channels = [ + channel.lower() for channel in (allowed_channels or []) + ] # Default for non-click functions _function: Union[Callable, click.Command] = self.function @@ -115,8 +112,8 @@ def __init__( if _function is not None: self.name = _function.__qualname__ - argspec = list(inspect.signature(_function).parameters.keys()) - if not argspec[:2] == ["self", "message"]: + argspec = list(inspect.signature(_function).parameters)[:2] + if argspec != ["self", "message"]: raise TypeError( "Any message listener function should at least have the positional" f" arguments `self` and `message`, but function {self.name} has" @@ -187,11 +184,9 @@ def listen_to( """Wrap the given function in a MessageFunction class so we can register some properties.""" - if allowed_users is None: - allowed_users = [] + allowed_users = allowed_users or [] - if allowed_channels is None: - allowed_channels = [] + allowed_channels = allowed_users or [] def wrapped_func(func): reg = regexp diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index 589bce96..fe8a589c 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -34,7 +34,7 @@ def expect_reply(driver: Driver, post: Dict, wait=RESPONSE_TIMEOUT, retries=1): reply = thread_info["posts"][reply_id] break - if not reply: + if reply is None: raise ValueError("Expected a response, but didn't get any!") return reply