python: use pyright

This commit is contained in:
link2xt
2023-02-20 10:33:51 +00:00
parent cdaef3bd0d
commit f2ab9456cd
7 changed files with 19 additions and 7 deletions

View File

@@ -55,3 +55,5 @@ line-length = 120
[tool.isort]
profile = "black"
[tool.pyright]

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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"):

View File

@@ -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)

View File

@@ -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 =