From 9d9a625b08336c0af2313ed44c6a496f8daa3928 Mon Sep 17 00:00:00 2001 From: haskal Date: Wed, 12 May 2021 16:02:26 -0400 Subject: [PATCH] fix some typing errors --- .flake8 | 2 ++ megacom/__init__.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7da1f96 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 100 diff --git a/megacom/__init__.py b/megacom/__init__.py index 24d6dbb..f2da0a2 100644 --- a/megacom/__init__.py +++ b/megacom/__init__.py @@ -1,13 +1,13 @@ import argparse import asyncio import contextlib -import os import re import sys import termios import tty from types import TracebackType -from typing import Optional, Tuple, Type +from typing import Any, List, Optional, Tuple, Type +from typing_extensions import Literal import serial import serial_asyncio @@ -30,11 +30,14 @@ MODE_LOOKUP = { class TtyRaw: __slots__ = ["isatty", "fd", "settings"] + isatty: bool + fd: int + settings: List[Any] def __init__(self) -> None: self.isatty = False - self.fd = None - self.settings = None + self.fd = 0 + self.settings = [] def __enter__(self) -> None: if sys.stdin.isatty(): @@ -46,9 +49,10 @@ class TtyRaw: def __exit__(self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], - exc_traceback: Optional[TracebackType]) -> bool: + exc_traceback: Optional[TracebackType]) -> Literal[False]: if self.isatty: termios.tcsetattr(self.fd, termios.TCSADRAIN, self.settings) + return False async def setup_async() -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: