diff --git a/pyproject.toml b/pyproject.toml index d42481f..8463410 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,10 +14,10 @@ python = "^3.8" python-telegram = "0.18.0" [tool.poetry.dev-dependencies] -black = "20.8b1" -flake8 = "3.8.4" -isort = "5.6.2" -mypy = "0.812" +black = "*" +flake8 = "*" +isort = "*" +mypy = "*" [tool.poetry.scripts] tg = "tg.__main__:main" diff --git a/tg/__main__.py b/tg/__main__.py index a7b1096..5381be3 100644 --- a/tg/__main__.py +++ b/tg/__main__.py @@ -1,9 +1,10 @@ import logging.handlers import signal import threading -from curses import window, wrapper # type: ignore +from curses import window, wrapper from functools import partial from types import FrameType +from typing import Optional from tg import config, update_handlers, utils from tg.controllers import Controller @@ -15,9 +16,8 @@ log = logging.getLogger(__name__) def run(tg: Tdlib, stdscr: window) -> None: - # handle ctrl+c, to avoid interrupting tg when subprocess is called - def interrupt_signal_handler(sig: int, frame: FrameType) -> None: + def interrupt_signal_handler(sig: int, frame: Optional[FrameType]) -> None: # TODO: draw on status pane: to quite press log.info("Interrupt signal is handled and ignored on purpose.") diff --git a/tg/config.py b/tg/config.py index 4d02df1..bf1f2bb 100644 --- a/tg/config.py +++ b/tg/config.py @@ -81,7 +81,7 @@ FILE_PICKER_CMD = "ranger --choosefile={file_path}" DOWNLOAD_DIR = os.path.expanduser("~/Downloads/") if os.path.isfile(CONFIG_FILE): - config_params = runpy.run_path(CONFIG_FILE) # type: ignore + config_params = runpy.run_path(CONFIG_FILE) for param, value in config_params.items(): if param.isupper(): globals()[param] = value diff --git a/tg/controllers.py b/tg/controllers.py index ef3f6a6..2715403 100644 --- a/tg/controllers.py +++ b/tg/controllers.py @@ -5,6 +5,7 @@ from datetime import datetime from functools import partial, wraps from queue import Queue from tempfile import NamedTemporaryFile +from types import FrameType from typing import Any, Callable, Dict, List, Optional from telegram.utils import AsyncResult @@ -303,8 +304,8 @@ class Controller: f.write(insert_replied_msg(msg)) f.seek(0) s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name))) - with open(f.name) as f: - if replied_msg := strip_replied_msg(f.read().strip()): + with open(f.name) as t: + if replied_msg := strip_replied_msg(t.read().strip()): self.model.view_all_msgs() self.tg.reply_message(chat_id, reply_to_msg, replied_msg) self.present_info("Message sent") @@ -336,8 +337,8 @@ class Controller: ) as s: self.tg.send_chat_action(chat_id, ChatAction.chatActionTyping) s.call(config.LONG_MSG_CMD.format(file_path=shlex.quote(f.name))) - with open(f.name) as f: - if msg := f.read().strip(): + with open(f.name) as t: + if msg := t.read().strip(): self.model.send_message(text=msg) self.present_info("Message sent") else: @@ -364,8 +365,8 @@ class Controller: try: with NamedTemporaryFile("w") as f, suspend(self.view) as s: s.call(config.FILE_PICKER_CMD.format(file_path=f.name)) - with open(f.name) as f: - file_path = f.read().strip() + with open(f.name) as t: + file_path = t.read().strip() except FileNotFoundError: pass if not file_path or not os.path.isfile(file_path): @@ -488,7 +489,7 @@ class Controller: chat = self.model.chats.chats[self.model.current_chat] return chat["permissions"]["can_send_messages"] - def _open_msg(self, msg: MsgProxy, cmd: str = None) -> None: + def _open_msg(self, msg: MsgProxy, cmd: Optional[str] = None) -> None: if msg.is_text: with NamedTemporaryFile("w", suffix=".txt") as f: f.write(msg.text_content) @@ -544,8 +545,8 @@ class Controller: f.write(msg.text_content) f.flush() s.call(f"{config.EDITOR} {f.name}") - with open(f.name) as f: - if text := f.read().strip(): + with open(f.name) as t: + if text := t.read().strip(): self.model.edit_message(text=text) self.present_info("Message edited") @@ -775,7 +776,7 @@ class Controller: except Exception: log.exception("Error happend in key handle loop") - def resize_handler(self, signum: int, frame: Any) -> None: + def resize_handler(self, signum: int, frame: Optional[FrameType]) -> None: self.view.resize_handler() self.resize() diff --git a/tg/models.py b/tg/models.py index d146ffa..ad1f252 100644 --- a/tg/models.py +++ b/tg/models.py @@ -403,7 +403,7 @@ class ChatModel: """ if self.have_full_chat_list: return None - offset_order = 2 ** 63 - 1 + offset_order = 2**63 - 1 offset_chat_id = 0 if len(self.chats): offset_chat_id = self.chats[-1]["id"] @@ -655,7 +655,6 @@ User = namedtuple("User", ["id", "name", "status", "order"]) class UserModel: - types = { "userTypeUnknown": "unknown", "userTypeBot": "bot", diff --git a/tg/msg.py b/tg/msg.py index 70bcded..461c66e 100644 --- a/tg/msg.py +++ b/tg/msg.py @@ -8,7 +8,6 @@ log = logging.getLogger(__name__) class MsgProxy: - fields_mapping = { "messageDocument": ("document", "document"), "messageVoiceNote": ("voice_note", "voice"), diff --git a/tg/tdlib.py b/tg/tdlib.py index 17b1023..0b637ff 100644 --- a/tg/tdlib.py +++ b/tg/tdlib.py @@ -345,12 +345,12 @@ class Tdlib(Telegram): return self._send_data(data) def send_chat_action( - self, chat_id: int, action: ChatAction, progress: int = None + self, chat_id: int, action: ChatAction ) -> AsyncResult: data = { "@type": "sendChatAction", "chat_id": chat_id, - "action": {"@type": action.name, "progress": progress}, + "action": {"@type": action.name}, } return self._send_data(data) diff --git a/tg/utils.py b/tg/utils.py index e895bf8..92ebeaa 100644 --- a/tg/utils.py +++ b/tg/utils.py @@ -22,7 +22,7 @@ from typing import Any, Dict, Optional, Tuple, Type from tg import config log = logging.getLogger(__name__) -units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12} +units = {"B": 1, "KB": 10**3, "MB": 10**6, "GB": 10**9, "TB": 10**12} class LogWriter: @@ -85,7 +85,9 @@ def get_file_handler(file_path: str) -> str: return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path)) caps = get_mailcap() - handler, view = mailcap.findmatch(caps, mtype, filename=shlex.quote(file_path)) + handler, view = mailcap.findmatch( + caps, mtype, filename=shlex.quote(file_path) + ) if not handler: return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path)) return handler @@ -230,7 +232,7 @@ class suspend: if proc.returncode: input(f"Command <{cmd}> failed: press to continue") - def open_file(self, file_path: str, cmd: str = None) -> None: + def open_file(self, file_path: str, cmd: Optional[str] = None) -> None: if cmd: cmd = cmd % shlex.quote(file_path) else: diff --git a/tg/views.py b/tg/views.py index 3facfc2..05a9a75 100644 --- a/tg/views.py +++ b/tg/views.py @@ -3,7 +3,7 @@ import logging from datetime import datetime from typing import Any, Dict, List, Optional, Tuple, Union, cast -from _curses import window # type: ignore +from _curses import window from tg import config from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow @@ -199,7 +199,7 @@ class ChatView: self, current: int, chats: List[Dict[str, Any]], title: str = "Chats" ) -> None: self.win.erase() - line = curses.ACS_VLINE # type: ignore + line = curses.ACS_VLINE width = self.w - 1 self.win.vline(0, width, line, self.h)