From 4e81c96dee89463e90661cdf5887bd2976b72dbc Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 29 Mar 2022 16:38:22 +0800 Subject: [PATCH] TypeHint --- danmaku_xml_helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/danmaku_xml_helper.py b/danmaku_xml_helper.py index e74ef5e..fe83f8f 100644 --- a/danmaku_xml_helper.py +++ b/danmaku_xml_helper.py @@ -1,6 +1,7 @@ import datetime import os import argparse +from typing import Union from bs4 import BeautifulSoup @@ -18,7 +19,7 @@ def check_file_exist(file): raise FileNotFoundError("文件不存在:%s" % file) -def get_file_start(file: os.PathLike[str]) -> float: +def get_file_start(file: Union[os.PathLike[str], str]) -> float: with open(file, "r", encoding="utf-8") as f: soup = BeautifulSoup("".join(f.readlines()), "lxml") danmaku_item = soup.find("d") @@ -34,7 +35,7 @@ def get_file_start(file: os.PathLike[str]) -> float: return bias_ts_ms / 1000 - bias_sec -def diff_danmaku_files(base_file: os.PathLike[str], file: os.PathLike[str]) -> float: +def diff_danmaku_files(base_file: Union[os.PathLike[str], str], file: Union[os.PathLike[str], str]) -> float: return get_file_start(file) - get_file_start(base_file)