Skip to content

Commit c13ffdb

Browse files
committed
fix: 清理Python文件中的重复注释
- 移除多个Python文件中的重复模块级和类级docstring - 修复测试文件中的重复注释问题 - 提升代码文档质量和可读性 - 影响文件包括:contributors/、examples/、tests/等目录下的80个文件
1 parent c3c2957 commit c13ffdb

80 files changed

Lines changed: 1818 additions & 660 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎contributors/CatchDr/Baidu_Text_transAPI.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,30 @@
1010
import requests
1111
import random
1212
from hashlib import md5
13-
def make_md5(s, encoding='utf-8'):
13+
def make_md5(s: str, encoding: str = 'utf-8') -> str:
14+
"""生成字符串的MD5哈希值。
15+
16+
Args:
17+
s (str): 要哈希的字符串
18+
encoding (str, optional): 编码格式,默认为'utf-8'
19+
20+
Returns:
21+
str: MD5哈希值
22+
"""
1423
return md5(s.encode(encoding)).hexdigest()
15-
def baidu_trans(query,from_lang,to_lang,appid,appkey):
16-
# Set your own appid/appkey.
24+
def baidu_trans(query, from_lang, to_lang, appid, appkey):
25+
"""调用百度翻译接口进行翻译。
26+
27+
Args:
28+
query (str): 需要翻译的文本
29+
from_lang (str): 源语言代码
30+
to_lang (str): 目标语言代码
31+
appid (str): 百度翻译API的应用ID
32+
appkey (str): 百度翻译API的密钥
33+
34+
Returns:
35+
str: 翻译后的文本
36+
"""
1737

1838

1939
# For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21`

‎contributors/CatchDr/doc2docx.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
import os # 目录的操作
1414

1515

16-
def createdocx(wordPath, docxPath):
16+
def createdocx(wordPath: str, docxPath: str) -> None:
17+
"""将Word文档转换为docx格式。
18+
19+
Args:
20+
wordPath (str): 原始Word文档路径
21+
docxPath (str): 转换后的docx文件路径
22+
"""
1723
# word = gencache.EnsureDispatch('Word.Application')
1824
# doc = word.Documents.Open(wordPath, ReadOnly=1)
1925
# # 转换方法
@@ -27,10 +33,13 @@ def createdocx(wordPath, docxPath):
2733
word.Quit()
2834

2935

30-
# 1、文件的批量转换
31-
# 自己指定路径,
32-
# 转换doc到docx
33-
def doc2docx(path, docSuffix=".doc"):
36+
def doc2docx(path: str, docSuffix: str = ".doc") -> None:
37+
"""批量将doc文件转换为docx格式。
38+
39+
Args:
40+
path (str): 文件路径或目录路径
41+
docSuffix (str, optional): doc文件后缀,默认为".doc"
42+
"""
3443
wordFiles = []
3544
# 如果不存在,则不做处理
3645
if not os.path.exists(path):

‎contributors/CatchDr/docx2doc.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515

1616

17-
def createdoc(wordPath, docxPath):
17+
def createdoc(wordPath: str, docxPath: str) -> None:
18+
"""将Word文档转换为DOC格式。
19+
20+
Args:
21+
wordPath (str): 源Word文档路径
22+
docxPath (str): 目标DOC文档路径
23+
24+
Returns:
25+
None
26+
"""
1827
# word = gencache.EnsureDispatch('Word.Application')
1928
# doc = word.Documents.Open(wordPath, ReadOnly=1)
2029
# # 转换方法
@@ -28,10 +37,16 @@ def createdoc(wordPath, docxPath):
2837
word.Quit()
2938

3039

31-
# 1、文件的批量转换
32-
# 自己指定路径,
33-
# 转换docx到doc
34-
def docx2doc(path, docxSuffix=".docx"):
40+
def docx2doc(path: str, docxSuffix: str = ".docx") -> None:
41+
"""批量将DOCX文档转换为DOC格式。
42+
43+
Args:
44+
path (str): 文件路径或目录路径
45+
docxSuffix (str, optional): DOCX文件后缀名,默认为".docx"
46+
47+
Returns:
48+
None
49+
"""
3550
wordFiles = []
3651
# 如果不存在,则不做处理
3752
if not os.path.exists(path):

‎contributors/CatchDr/ppt2pptx.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
import win32com
1313
import os # 目录的操作
1414

15-
def createpptx(pptPath, pptxPath):
15+
def createpptx(pptPath: str, pptxPath: str) -> None:
16+
"""将PPT文档转换为PPTX格式。
17+
18+
Args:
19+
pptPath (str): 源PPT文档路径
20+
pptxPath (str): 目标PPTX文档路径
21+
22+
Returns:
23+
None
24+
"""
1625
powerpoint = win32com.client.Dispatch('PowerPoint.Application')
1726
win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
1827
# powerpoint.Visible = 1
@@ -22,10 +31,16 @@ def createpptx(pptPath, pptxPath):
2231
powerpoint.Quit()
2332

2433

25-
# 1、文件的批量转换
26-
# 自己指定路径,
27-
# 转换ppt到pptx
28-
def ppt2pptx(path, docxSuffix=".poppt"):
34+
def ppt2pptx(path: str, docxSuffix: str = ".poppt") -> None:
35+
"""批量将PPT文档转换为PPTX格式。
36+
37+
Args:
38+
path (str): 文件路径或目录路径
39+
docxSuffix (str, optional): PPT文件后缀名,默认为".poppt"
40+
41+
Returns:
42+
None
43+
"""
2944
pptFiles = []
3045
# 如果不存在,则不做处理
3146
if not os.path.exists(path):

‎contributors/CatchDr/pptx2ppt.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
import win32com
1313
import os # 目录的操作
1414

15-
def createppt(pptxPath, pptPath):
15+
def createppt(pptxPath: str, pptPath: str) -> None:
16+
"""将PPTX文档转换为PPT格式。
17+
18+
Args:
19+
pptxPath (str): 源PPTX文档路径
20+
pptPath (str): 目标PPT文档路径
21+
22+
Returns:
23+
None
24+
"""
1625
powerpoint = win32com.client.Dispatch('PowerPoint.Application')
1726
win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
1827
# powerpoint.Visible = 1
@@ -22,10 +31,16 @@ def createppt(pptxPath, pptPath):
2231
powerpoint.Quit()
2332

2433

25-
# 1、文件的批量转换
26-
# 自己指定路径,
27-
# 转换pptx到ppt
28-
def pptx2ppt(path, docxSuffix=".pptx"):
34+
def pptx2ppt(path: str, docxSuffix: str = ".pptx") -> None:
35+
"""批量将PPTX文档转换为PPT格式。
36+
37+
Args:
38+
path (str): 文件路径或目录路径
39+
docxSuffix (str, optional): PPTX文件后缀名,默认为".pptx"
40+
41+
Returns:
42+
None
43+
"""
2944
pptxFiles = []
3045
# 如果不存在,则不做处理
3146
if not os.path.exists(path):

‎contributors/CatchDr/video_time_statistics.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
import datetime
1212
from moviepy.editor import VideoFileClip
1313
from tqdm import tqdm
14-
def video_time_statistics(path):
14+
def video_time_statistics(path: str) -> None:
15+
"""统计指定目录下所有MP4视频文件的总时长。
16+
17+
Args:
18+
path (str): 要统计视频时长的目录路径
19+
20+
Returns:
21+
None
22+
"""
1523
filelist = []
1624
for a, b, c in os.walk(path):
1725
for name in c:

‎contributors/CatchDr/xls2xlsx.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414

1515

1616

17-
def createxlsx(xlsPath, xlsxPath):
18-
17+
def createxlsx(xlsPath: str, xlsxPath: str) -> None:
18+
"""将XLS文档转换为XLSX格式。
19+
20+
Args:
21+
xlsPath (str): 源XLS文档路径
22+
xlsxPath (str): 目标XLSX文档路径
23+
24+
Returns:
25+
None
26+
"""
1927
excel = win32com.client.DispatchEx('Excel.Application')
2028
wb = excel.Workbooks.Open(xlsPath)
2129

@@ -25,10 +33,16 @@ def createxlsx(xlsPath, xlsxPath):
2533

2634

2735

28-
# 1、文件的批量转换
29-
# 自己指定路径,
30-
# 转换xls到xlsx
31-
def xls2xlsx(path, docxSuffix=".xls"):
36+
def xls2xlsx(path: str, docxSuffix: str = ".xls") -> None:
37+
"""批量将XLS文档转换为XLSX格式。
38+
39+
Args:
40+
path (str): 文件路径或目录路径
41+
docxSuffix (str, optional): XLS文件后缀名,默认为".xls"
42+
43+
Returns:
44+
None
45+
"""
3246
excelFiles = []
3347
# 如果不存在,则不做处理
3448
if not os.path.exists(path):

‎contributors/CatchDr/xlsx2xls.py‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212
import win32com
1313
import os # 目录的操作
1414

15-
def createxls(xlsxPath, xlsPath):
16-
15+
def createxls(xlsxPath: str, xlsPath: str) -> None:
16+
"""将XLSX文档转换为XLS格式。
17+
18+
Args:
19+
xlsxPath (str): 源XLSX文档路径
20+
xlsPath (str): 目标XLS文档路径
21+
22+
Returns:
23+
None
24+
"""
1725
excel = win32com.client.DispatchEx('Excel.Application')
1826
wb = excel.Workbooks.Open(xlsxPath)
1927

@@ -22,10 +30,16 @@ def createxls(xlsxPath, xlsPath):
2230
excel.Application.Quit()
2331

2432

25-
# 1、文件的批量转换
26-
# 自己指定路径,
27-
# 转换xlsx到xls
28-
def xlsx2xls(path, docxSuffix=".xlsx"):
33+
def xlsx2xls(path: str, docxSuffix: str = ".xlsx") -> None:
34+
"""批量将XLSX文档转换为XLS格式。
35+
36+
Args:
37+
path (str): 文件路径或目录路径
38+
docxSuffix (str, optional): XLSX文件后缀名,默认为".xlsx"
39+
40+
Returns:
41+
None
42+
"""
2943
excelFiles = []
3044
# 如果不存在,则不做处理
3145
if not os.path.exists(path):

‎contributors/bulabean/SearchExcel.py‎

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77

88
def change_datatype(row_data: list):
9-
"""
10-
excel单元格的内容类型检测和转换
11-
参数:
12-
row_data:行数据,列表格式
9+
"""Excel单元格的内容类型检测和转换。
10+
11+
Args:
12+
row_data (list): 行数据,列表格式
13+
14+
Returns:
15+
list: 转换后的行数据
1316
"""
1417
result_data = []
1518
for rd in row_data:
@@ -30,11 +33,14 @@ def change_datatype(row_data: list):
3033

3134

3235
def find_key(search_key: str, row_content: str):
33-
"""
34-
检测关键词和内容
35-
参数:
36-
search_key:关键词
37-
row_content:行内容
36+
"""检测关键词和内容。
37+
38+
Args:
39+
search_key (str): 关键词
40+
row_content (str): 行内容
41+
42+
Returns:
43+
bool: 如果包含关键词返回True,否则返回False
3844
"""
3945
if search_key in row_content:
4046
return True
@@ -43,11 +49,14 @@ def find_key(search_key: str, row_content: str):
4349

4450

4551
def process_xls(path, file):
46-
"""
47-
读取xls后缀的excel文件
48-
参数:
49-
path:文件所在路径
50-
file:文件名
52+
"""读取xls后缀的Excel文件。
53+
54+
Args:
55+
path (str): 文件所在路径
56+
file (str): 文件名
57+
58+
Yields:
59+
tuple: 包含文件路径、工作表名、行数、行内容的元组
5160
"""
5261
filepath = os.path.join(path, file)
5362
try:
@@ -74,11 +83,14 @@ def process_xls(path, file):
7483

7584

7685
def process_xlsx(path, file):
77-
"""
78-
读取xlsx后缀的excel文件
79-
参数:
80-
path:文件所在路径
81-
file:文件名
86+
"""读取xlsx后缀的Excel文件。
87+
88+
Args:
89+
path (str): 文件所在路径
90+
file (str): 文件名
91+
92+
Yields:
93+
tuple: 包含文件路径、工作表名、行数、行内容的元组
8294
"""
8395
filepath = os.path.join(path, file)
8496
try:
@@ -103,11 +115,14 @@ def process_xlsx(path, file):
103115

104116

105117
def find_excel_data(search_key: str, target_dir: str):
106-
"""
107-
检索指定目录下的excel文件和过滤
108-
参数:
109-
search_key:检索的关键词
110-
target_dir:目标文件夹
118+
"""检索指定目录下的Excel文件和过滤。
119+
120+
Args:
121+
search_key (str): 检索的关键词
122+
target_dir (str): 目标文件夹
123+
124+
Yields:
125+
tuple: 包含文件路径、工作表名、行数、行内容的元组
111126
"""
112127
for path, dirs, files in os.walk(target_dir):
113128
files = [file for file in files if not file.startswith('~$')] # 过滤掉正打开的excel文件

0 commit comments

Comments
 (0)