fix some typing errors

This commit is contained in:
xenia 2021-05-12 16:02:26 -04:00
parent 4eecac0c56
commit 9d9a625b08
2 changed files with 11 additions and 5 deletions

2
.flake8 Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 100

View File

@ -1,13 +1,13 @@
import argparse import argparse
import asyncio import asyncio
import contextlib import contextlib
import os
import re import re
import sys import sys
import termios import termios
import tty import tty
from types import TracebackType 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
import serial_asyncio import serial_asyncio
@ -30,11 +30,14 @@ MODE_LOOKUP = {
class TtyRaw: class TtyRaw:
__slots__ = ["isatty", "fd", "settings"] __slots__ = ["isatty", "fd", "settings"]
isatty: bool
fd: int
settings: List[Any]
def __init__(self) -> None: def __init__(self) -> None:
self.isatty = False self.isatty = False
self.fd = None self.fd = 0
self.settings = None self.settings = []
def __enter__(self) -> None: def __enter__(self) -> None:
if sys.stdin.isatty(): if sys.stdin.isatty():
@ -46,9 +49,10 @@ class TtyRaw:
def __exit__(self, exc_type: Optional[Type[BaseException]], def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException], exc_value: Optional[BaseException],
exc_traceback: Optional[TracebackType]) -> bool: exc_traceback: Optional[TracebackType]) -> Literal[False]:
if self.isatty: if self.isatty:
termios.tcsetattr(self.fd, termios.TCSADRAIN, self.settings) termios.tcsetattr(self.fd, termios.TCSADRAIN, self.settings)
return False
async def setup_async() -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: async def setup_async() -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]: