Skip to content

Commit

Permalink
fix 889f81a, better logic/type-hints, update mypy comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed Jun 21, 2023
1 parent 79e4fdf commit 123f7ec
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sopel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


if TYPE_CHECKING:
from collections.abc import Iterable
from sopel.bot import SopelWrapper

__all__ = [
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 123f7ec

Please sign in to comment.