Skip to content

Commit 9bbe5da

Browse files
committed
Lint & Format
1 parent f6d308e commit 9bbe5da

8 files changed

Lines changed: 106 additions & 12 deletions

File tree

detection/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

detection/checker.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,65 @@
1+
"""
2+
定义检查器,
3+
用预定义与自定义的子检查器传参初始化,
4+
调用检查函数,
5+
返回特定结果。
6+
"""
7+
18
from collections.abc import Callable
29
from typing import Self
310

411
type Checker_t = Callable[[tuple], bool]
512

613

714
class Checker:
8-
results = dict()
15+
"""
16+
检查器
17+
"""
18+
19+
results = {}
920

1021
def __init__(self, SubCheckers: dict[Checker_t, str]) -> None:
22+
"""
23+
初始化
24+
:param SubCheckers: 子检查器字典, 绑定错误信息
25+
"""
1126
self.subCheckers = SubCheckers
1227

1328
def execTask(self, Content: tuple) -> Self:
29+
"""
30+
调用检查函数
31+
:param Content: 待检查内容
32+
"""
1433
for func in self.subCheckers.keys():
1534
self.results[func] = func(Content)
1635
return self
1736

1837
def getResults(self) -> dict[Checker_t, bool]:
38+
"""
39+
获取结果(bool 返回值)
40+
:return: 检查函数绑定返回值的字典
41+
"""
1942
return self.results
2043

2144
def __bool__(self) -> bool:
2245
return all(self.results.values())
2346

2447
def __str__(self) -> str:
25-
tmp = list()
48+
tmp = []
2649
for func, result in self.results.items():
2750
if not result:
2851
tmp.append(self.subCheckers[func])
2952
return ";".join(tmp)
3053

3154

3255
class CheckerNoMsg(Checker):
56+
"""
57+
继承 Checker, 不传检查信息
58+
"""
59+
3360
def __init__(self, SubCheckers: tuple[Checker_t, ...]) -> None:
34-
self.subCheckers = {SubChecker: "" for SubChecker in SubCheckers}
61+
"""
62+
初始化
63+
:param SubCheckers: 仅包含子检查器的元组
64+
"""
65+
super().__init__(SubCheckers={SubChecker: "" for SubChecker in SubCheckers})

detection/subCheckers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1+
"""
2+
预定义子检查器
3+
"""
4+
5+
16
def isNotSpace(Content: tuple[str]) -> bool:
7+
"""
8+
判断是否为空串
9+
包装 str.isspace()
10+
:param Content: 待检查内容
11+
:return: 若不是空串则返回真
12+
"""
213
return not Content[0].isspace()
314

415

516
def isNum(Content: tuple[str]) -> bool:
17+
"""
18+
判断字符串内容是否为十进制整数
19+
包装 str.isdecimal(), 允许前后空字符和一位符号前缀(+/-)
20+
:param Content: 待检查内容
21+
:return: 若是十进制整数则返回真
22+
"""
623
return any(Content[0].strip().removeprefix(prefix).isdecimal() for prefix in "+-")
724

825

926
def isNotNegative(Content: tuple[str]) -> bool:
27+
"""
28+
判断十进制整数是否为非负数
29+
调用 .isNum 判断十进制整数
30+
:param Content: 待检查内容
31+
:return: 若是十进制非负整数则返回真
32+
"""
1033
return isNum(Content) and Content[0].strip()[0] != "-"

generation/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
"""
2+
定义模块常量
3+
"""
4+
15
BOX_CAPACITY = 27

generation/constructor.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# pylint: disable = C0301, R0903
2+
"""
3+
定义地图与箱子的简单构造对象和构造器
4+
"""
5+
6+
17
class Map:
8+
"""
9+
简单地图构造对象
10+
"""
11+
212
TEMPLATE = '{{Count:1b,Slot:{Slot}b,id:"minecraft:filled_map",tag:{{map:{MapId}}}}}'
313

414
def __init__(self, Slot: int, MapId: int) -> None:
@@ -10,6 +20,10 @@ def __str__(self) -> str:
1020

1121

1222
class Box:
23+
"""
24+
简单箱子构造对象
25+
"""
26+
1327
TEMPLATE = '{{Count:1b,{Slot}id:"minecraft:chest",tag:{{BlockEntityTag:{{Items:{Items},id:"minecraft:chest"}},display:{{Name:\'{{"Italic":false,"Extra":[{{"text":""}},{{"color":"dark_gray","text":"["}},{{"color":"dark_aqua","text":"{Begin}"}},{{"color":"gray","text":","}},{{"color":"aqua","text":"{End}"}},{{"color":"dark_gray","text":")"}}],"text":""}}\'}}}}}}'
1428

1529
def __init__(self, Begin: int, End: int, Slot: int = -1) -> None:
@@ -30,4 +44,8 @@ def __str__(self) -> str:
3044

3145

3246
class Constructor(Box):
33-
pass
47+
"""
48+
构造器
49+
继承自 Box
50+
完全等同
51+
"""

generation/iterator.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
"""
2+
定义迭代(生成)器
3+
"""
4+
15
from . import BOX_CAPACITY
2-
from .constructor import Box, Map
6+
from .constructor import Box, Map # pylint: disable = R0401
37

48

59
def iterator(Begin: int, End: int) -> list[Map | Box]:
10+
"""
11+
迭代(生成)器
12+
通过传入左闭右开区间得到对象
13+
:param Begin: 地图起始编号
14+
:param End: 地图结束编号
15+
:return: 装有 Map/Box 对象的列表
16+
"""
617
from math import ceil, log
718

819
step = BOX_CAPACITY ** ceil(log(End - Begin, 27) - 1) if End - Begin > 1 else 1

main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
"""
2+
main
3+
"""
4+
5+
import pyperclip
16
from detection.checker import CheckerNoMsg as Checker
27
from detection.subCheckers import isNotSpace, isNum, isNotNegative
38
from generation.constructor import Constructor
49

5-
import pyperclip
6-
7-
810
mapId = input("输入第一张地图画的编号:\n")
911
mapNum = input("输入需遍历的地图画数量:\n")
1012

@@ -29,8 +31,6 @@
2931
try:
3032
pyperclip.copy(strBox)
3133
except pyperclip.PyperclipException as exception:
32-
print(
33-
f"复制失败!\n请手动复制到剪贴板\n以下是pyperclip原始报错信息:\n{exception}"
34-
)
34+
print(f"复制失败!\n请手动复制到剪贴板\n以下是pyperclip原始报错信息:\n{exception}")
3535
else:
3636
print("已复制到剪贴板!")

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool.black]
2+
line-length = 100
3+
unstable = true
4+
5+
[tool.pylint.main]
6+
disable = ["invalid-name", "import-outside-toplevel"]
7+
[tool.pylint.format]
8+
max-line-length = 100

0 commit comments

Comments
 (0)