Skip to content

Commit

Permalink
lint & type checking
Browse files Browse the repository at this point in the history
Warning: match-case isn't support by ruff yet.
astral-sh/ruff#282
  • Loading branch information
YDX-2147483647 committed Feb 2, 2023
1 parent eab1f99 commit 8c5def7
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"charliermarsh.ruff"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"isin",
"lxml"
],
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black"
}
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ undo:
# See what has changed in VS Code
diff:
code --diff output/message-old.txt output/message.txt

# Check errors for the local package
check:
-{{ python }} -m black .
-{{ python }} -m ruff .
-{{ python }} -m mypy .
145 changes: 144 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ openpyxl = "^3.0.10"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
ruff = "^0.0.239"
mypy = "^0.991"
types-requests = "^2.28.11.8"
types-beautifulsoup4 = "^4.11.6.5"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
line-length = 88

[tool.mypy]
ignore_missing_imports = true
Empty file added watch_exams/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion watch_exams/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update_file(message: str, output_file: Path, old_output_file: Path) -> None:
)

if output_file.exists():
old_message = output_file.read_text(encoding="utf-8")
old_message: str | None = output_file.read_text(encoding="utf-8")
else:
old_message = None

Expand Down
5 changes: 3 additions & 2 deletions watch_exams/fetch_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_plan_info(**requests_args) -> PlanInfo:

soup = BeautifulSoup(req.text, features="lxml")
plan_element = soup.select(".pageArticle > .Annex > ul > li > a:not([download])")[1]
url = urljoin(notification_url, plan_element.get("href")) # type: ignore
url: str = urljoin(notification_url, plan_element.get("href")) # type: ignore

filename = plan_element.get_text()
assert "学生" in filename and "考试安排" in filename
Expand All @@ -45,7 +45,8 @@ def get_plan_info(**requests_args) -> PlanInfo:
def get_watched_plans(url: str, watches: list[str], **requests_args) -> DataFrame:
"""
Returns:
The data with Index(['学号', '姓名', '课程号', '课程名', '考试序号', '考试时间', '其他说明', '通知单类型']).
The data with the following indices.
"学号", "姓名", "课程号", "课程名", "考试序号", "考试时间", "其他说明", "通知单类型"
"""

res = fetch(url, **requests_args)
Expand Down
2 changes: 0 additions & 2 deletions watch_exams/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def ding(markdown: str, secrets_file: Path) -> None:
"""向钉钉发送 Markdown"""

with open(secrets_file, "r", encoding="utf-8") as f:
access_token: Final
secret: Final
access_token, secret = [
line.strip() for line in f.readlines() if not line.startswith("#")
]
Expand Down

0 comments on commit 8c5def7

Please sign in to comment.