diff --git a/python/pyproject.toml b/python/pyproject.toml index 4aa6666db..a41e7aeec 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -55,3 +55,5 @@ line-length = 120 [tool.isort] profile = "black" + +[tool.pyright] diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index e666b6cd4..4c53505fb 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -463,9 +463,10 @@ class Chat: :returns: None """ contact = self.account.get_contact(obj) - ret = lib.dc_remove_contact_from_chat(self.account._dc_context, self.id, contact.id) - if ret != 1: - raise ValueError(f"could not remove contact {contact!r} from chat") + if contact: + ret = lib.dc_remove_contact_from_chat(self.account._dc_context, self.id, contact.id) + if ret != 1: + raise ValueError("could not remove contact {contact!r} from chat") def get_contacts(self): """get all contacts for this chat. diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index d95bd29ab..fc35a32e0 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -147,7 +147,7 @@ class DirectImap: log("Message", msg.uid, "has empty body") continue - path = pathlib.Path(str(dir)).joinpath("IMAP", self.logid, imapfolder) + path = pathlib.Path(str(dir)).joinpath("IMAP", str(self.logid), imapfolder) path.mkdir(parents=True, exist_ok=True) fn = path.joinpath(str(msg.uid)) fn.write_bytes(body) diff --git a/python/src/deltachat/events.py b/python/src/deltachat/events.py index 006095da0..937d48bb7 100644 --- a/python/src/deltachat/events.py +++ b/python/src/deltachat/events.py @@ -111,11 +111,12 @@ class FFIEventTracker: while True: yield self.get(timeout=timeout, check_error=check_error) - def get_matching(self, event_name_regex, check_error=True, timeout=None): + def get_matching(self, event_name_regex, check_error=True, timeout=None) -> FFIEvent: rex = re.compile(f"^(?:{event_name_regex})$") for ev in self.iter_events(timeout=timeout, check_error=check_error): if rex.match(ev.name): return ev + assert False def get_info_contains(self, regex: str) -> FFIEvent: rex = re.compile(regex) @@ -123,6 +124,7 @@ class FFIEventTracker: ev = self.get_matching("DC_EVENT_INFO") if rex.search(ev.data2): return ev + assert False def get_info_regex_groups(self, regex, check_error=True): rex = re.compile(regex) diff --git a/python/src/deltachat/testplugin.py b/python/src/deltachat/testplugin.py index ebbb13aaf..a1a010e17 100644 --- a/python/src/deltachat/testplugin.py +++ b/python/src/deltachat/testplugin.py @@ -250,7 +250,7 @@ def data(request): fn = os.path.join(path, *bn.split("/")) if os.path.exists(fn): return fn - print(f"WARNING: path does not exist: {fn!r}") + print(f"WARNING: path does not exist: {request!r}") return None def read_path(self, bn, mode="r"): diff --git a/python/tests/test_2_increation.py b/python/tests/test_2_increation.py index c7e35119a..f02fdc63f 100644 --- a/python/tests/test_2_increation.py +++ b/python/tests/test_2_increation.py @@ -1,6 +1,7 @@ import os.path import shutil from filecmp import cmp +from typing import Optional import pytest @@ -13,7 +14,7 @@ def wait_msg_delivered(account, msg_list): msg_list.remove((ev.data1, ev.data2)) -def wait_msgs_changed(account, msgs_list): +def wait_msgs_changed(account, msgs_list: list[tuple[int, Optional[int]]]): """wait for one or more MSGS_CHANGED events to match msgs_list contents.""" account.log(f"waiting for msgs_list={msgs_list}") msgs_list = list(msgs_list) diff --git a/python/tox.ini b/python/tox.ini index 6a50005c5..a996a319d 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -5,6 +5,7 @@ envlist = lint mypy auditwheels + pyright [testenv] commands = @@ -25,6 +26,7 @@ deps = pytest-xdist pdbpp requests + pyright: pyright [testenv:.pkg] passenv = @@ -68,6 +70,10 @@ deps = commands = mypy --no-incremental src/ +[testenv:pyright] +commands = + pyright + [testenv:doc] changedir=doc deps =