diff --git a/sopel/plugin.py b/sopel/plugin.py index 7d6aa368c..b3c005d17 100644 --- a/sopel/plugin.py +++ b/sopel/plugin.py @@ -29,6 +29,7 @@ if TYPE_CHECKING: + from collections.abc import Iterable from sopel.bot import SopelWrapper __all__ = [ @@ -1773,23 +1774,23 @@ class example: def __init__( self, msg: str, - result: Optional[Union[str, List[str]]] = None, + result: Optional[Union[str, Iterable[str]]] = None, privmsg: bool = False, admin: bool = False, owner: bool = False, repeat: int = 1, re: bool = False, - ignore: Optional[Union[str, List[str]]] = None, + ignore: Optional[Union[str, Iterable[str]]] = None, user_help: bool = False, online: bool = False, vcr: bool = False, ): # Wrap result into a list for get_example_test - self.result: Optional[List[str]] = None - if isinstance(result, list): - self.result = result - elif result is not None: + self.result: Optional[list[str]] = None + if isinstance(result, str): self.result = [result] + elif result is not None: + self.result = list(result) self.use_re = re self.msg = msg @@ -1800,17 +1801,16 @@ def __init__( self.online = online self.vcr = vcr - if isinstance(ignore, list): - self.ignore = ignore - elif ignore is not None: + self.ignore: list[str] = [] + if isinstance(ignore, str): self.ignore = [ignore] - else: - self.ignore = [] + elif ignore is not None: + self.ignore = list(ignore) self.user_help = user_help def __call__(self, func): - # mypy (as of v1.3) doesn't recognize the below check as adding an + # mypy (as of v1.4) doesn't recognize the below check as adding an # "example" attribute to `func` if it's missing, so the `func` # argument isn't typed yet. # When we're ready to type-hint `loader`, we can make a TypeVar like