mirror of
https://github.com/scito/extract_otp_secret_keys
synced 2024-11-04 12:00:14 +00:00
type hinting fixes
This commit is contained in:
parent
58fc1b85ac
commit
fb43c6793c
@ -6,3 +6,4 @@ pytest-mock
|
||||
pytest-cov
|
||||
mypy
|
||||
types-protobuf
|
||||
setuptools
|
||||
|
1
setup.py
1
setup.py
@ -1,4 +1,3 @@
|
||||
from __future__ import annotations # for compatibility with Python < 3.11
|
||||
import pathlib
|
||||
from setuptools import setup
|
||||
|
||||
|
15
utils.py
15
utils.py
@ -22,7 +22,7 @@ import re
|
||||
import shutil
|
||||
import sys
|
||||
import pathlib
|
||||
from typing import BinaryIO, Any, Union
|
||||
from typing import BinaryIO, Any, Union, List
|
||||
|
||||
|
||||
# Types
|
||||
@ -31,7 +31,8 @@ PathLike = Union[str, pathlib.Path]
|
||||
|
||||
|
||||
# Ref. https://stackoverflow.com/a/16571630
|
||||
class Capturing(list[Any]):
|
||||
# PYTHON 3.11: class Capturing(list[Any]):
|
||||
class Capturing(List[Any]):
|
||||
'''Capture stdout and stderr
|
||||
Usage:
|
||||
with Capturing() as output:
|
||||
@ -72,19 +73,19 @@ def remove_dir_with_files(dir: PathLike) -> None:
|
||||
if os.path.exists(dir): shutil.rmtree(dir)
|
||||
|
||||
|
||||
def read_csv(filename: str) -> list[list[str]]:
|
||||
def read_csv(filename: str) -> List[List[str]]:
|
||||
"""Returns a list of lines."""
|
||||
with open(filename, "r", encoding="utf-8", newline='') as infile:
|
||||
lines: list[list[str]] = []
|
||||
lines: List[List[str]] = []
|
||||
reader = csv.reader(infile)
|
||||
for line in reader:
|
||||
lines.append(line)
|
||||
return lines
|
||||
|
||||
|
||||
def read_csv_str(data_str: str) -> list[list[str]]:
|
||||
def read_csv_str(data_str: str) -> List[List[str]]:
|
||||
"""Returns a list of lines."""
|
||||
lines: list[list[str]] = []
|
||||
lines: List[List[str]] = []
|
||||
reader = csv.reader(data_str.splitlines())
|
||||
for line in reader:
|
||||
lines.append(line)
|
||||
@ -102,7 +103,7 @@ def read_json_str(data_str: str) -> Any:
|
||||
return json.loads(data_str)
|
||||
|
||||
|
||||
def read_file_to_list(filename: str) -> list[str]:
|
||||
def read_file_to_list(filename: str) -> List[str]:
|
||||
"""Returns a list of lines."""
|
||||
with open(filename, "r", encoding="utf-8") as infile:
|
||||
return infile.readlines()
|
||||
|
Loading…
Reference in New Issue
Block a user