Skip to content

Commit 99d4fa1

Browse files
committed
🔧 update type hints for query parameters and update ruff lint rules
1 parent b4dd382 commit 99d4fa1

File tree

3 files changed

+81
-16
lines changed

3 files changed

+81
-16
lines changed

nonebot_plugin_paper/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require("nonebot_plugin_apscheduler")
88
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
99

10-
from .command import paper_cmd # noqa
10+
from .command import paper_cmd # noqa: F401
1111
from .config import Config
1212
from .utils import connection_verification
1313

nonebot_plugin_paper/command.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from aioarxiv.client.arxiv_client import ArxivClient, SortCriterion, SortOrder
24
from arclet.alconna import Alconna, Args, Subcommand
35
from nonebot.log import logger
@@ -47,9 +49,9 @@ async def handle_search(
4749
uninfo: Uninfo,
4850
unimsg: UniMsg,
4951
number: Query[int] = AlconnaQuery("number", 1),
50-
sort: Query[SortCriterion | None] = AlconnaQuery("sort", None),
51-
order: Query[SortOrder | None] = AlconnaQuery("order", None),
52-
start: Query[int | None] = AlconnaQuery("start", None),
52+
sort: Query[Optional[SortCriterion]] = AlconnaQuery("sort", None),
53+
order: Query[Optional[SortOrder]] = AlconnaQuery("order", None),
54+
start: Query[Optional[int]] = AlconnaQuery("start", None),
5355
):
5456
logger.debug(f"Searching for {keyword} by {uninfo.user.id}")
5557
async with ArxivClient() as client:
@@ -68,10 +70,10 @@ async def handle_search(
6870

6971

7072
@paper_cmd.assign("id")
71-
async def handle_id(id: str, state: T_State, uninfo: Uninfo, unimsg: UniMsg):
72-
logger.debug(f"Searching for {id} by {uninfo.user.id}")
73+
async def handle_id(paper_id: str, state: T_State, uninfo: Uninfo, unimsg: UniMsg):
74+
logger.debug(f"Searching for {paper_id} by {uninfo.user.id}")
7375
img = await capture_element(
74-
f"https://arxiv.org/abs/{id}",
76+
f"https://arxiv.org/abs/{paper_id}",
7577
element="#abs-outer > div.leftcolumn",
7678
)
7779
await UniMessage(Image(raw=img)).finish(reply_to=True)

pyproject.toml

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,95 @@ line-ending = "lf"
7575

7676
[tool.ruff.lint]
7777
select = [
78-
"F", # Pyflakes
79-
"W", # pycodestyle warnings
78+
"F", # pyflakes
8079
"E", # pycodestyle errors
80+
"W", # pycodestyle warnings
8181
"I", # isort
82+
"N", # PEP8-naming
8283
"UP", # pyupgrade
84+
"YTT", # flake8-2020
8385
"ASYNC", # flake8-async
86+
# "S", # flake8-bandit
87+
"BLE", # flake8-blind-except
88+
# "FBT", # flake8-boolean-trap
8489
"B", # flake8-bugbear
90+
"A", # flake8-builtins
91+
"COM", # flake8-commas
8592
"C4", # flake8-comprehensions
8693
"DTZ", # flake8-datetimez
8794
"T10", # flake8-debugger
95+
# "FA", # flake8-future-annotations
96+
"ISC", # flake8-implicit-str-concat
97+
"ICN", # flake8-import-conventions
98+
"PIE", # flake8-pie
8899
"T20", # flake8-print
89100
"PYI", # flake8-pyi
90-
"PT", # flake8-pytest-style
91101
"Q", # flake8-quotes
102+
"RSE", # flake8-raise
103+
"RET", # flake8-return
104+
"SLOT", # flake8-slots
92105
"SIM", # flake8-simplify
93106
"TID", # flake8-tidy-imports
94-
"PLE", # Pylint errors
95-
"NPY", # NumPy-specific rules
107+
# "TC", # flake8-type-checking
108+
# "ARG", # flake8-unused-arguments
109+
"PTH", # flake8-use-pathlib
110+
# "ERA", # eradicate
111+
"PD", # pandas-vet
112+
"PGH", # pygrep-hooks
113+
"PL", # pylint
114+
"TRY", # tryceratops
115+
"FLY", # flynt
116+
"FAST", # FastAPI
117+
"PERF", # Perflint
118+
"FURB", # refurb
96119
"RUF", # Ruff-specific rules
97120
]
98121
ignore = [
99-
"E402", # module-import-not-at-top-of-file
100-
"RUF001", # ambiguous-unicode-character-string
101-
"RUF002", # ambiguous-unicode-character-docstring
102-
"RUF003", # ambiguous-unicode-character-comment
122+
"C901",
123+
"T201",
124+
"E731",
125+
"PT023",
126+
"B010", # Do not call `setattr` with a constant attribute value.
127+
"SIM105", # Use `contextlib.suppress`
128+
"B008", # Do not perform function call in argument defaults
129+
"RUF100", # Unused `noqa` directive
130+
"TC003", # Move xxx into a type-checking block
131+
"E402", # module level import not at top of file
132+
"E501", # 过长的行由 ruff format 处理, 剩余的都是字符串
133+
"UP035", # pyupgrade, 但 typing.Callable 的导入会报错
134+
"TRY003",
135+
"TRY301", # 为啥非要把 raise 丢进另外一个 inner fn 里
136+
"BLE001", # except Exception as e
137+
"PGH003", # 要求 `# type: ignore` 提供理由,但 pyright 和 mypy 等都不是统一标准。
138+
"PLC0414", # 用 import-as 表示 re-export
139+
"N818", # 要求所有自定义错误以 Error 作后缀,但我们不这么做
140+
"RET502", # return = return None
141+
"RET503", # 就要 implicit return none
142+
"PLC0105", # 我们已经用 R 表示协变,Q 表示逆变了
143+
"PLR0913", # 参数就那么多的,你用 builder 什么的不是更逆天?
144+
"SIM108", # 迫真 simplicy
145+
"RUF001", # String contains ambiguous `,` (FULLWIDTH COMMA). Did you mean `,` (COMMA)?
146+
"RUF002", # Docstring contains ambiguous `,` (FULLWIDTH COMMA). Did you mean `,` (COMMA)?
147+
"RUF009", # 我不想要额外的全局变量。
148+
"UP038", # instance(..., X | Y) 还是太超前了
149+
"RUF003", # 中文注释里用全角符号怎么你了
150+
"SLOT000", # 动态类型需求,主要是 json5 backend
151+
"PLR0911", "PLR0912", "PLR0915", # 复杂度高点怎么你了
152+
"PYI041", # int 和 float 在运行时的类型没有交集(互不成立 issubclass)
153+
"PLW2901", # shallow 怎么你了
154+
"S101", # assert 怎么你了,非要 RuntimeError 吗
155+
"PLR2004", # magic number 怎么你了
156+
"TRY004", # 我要抛啥错误我清楚
157+
"COM812", # 强制尾随逗号
158+
"TID252", # 相对导入
159+
"ISC001", # format warning
160+
"N801", # Class name should use CapWords convention
161+
"N802", # Function name should be lowercase
162+
"N804", # First argument of a class method should be named `cls`
163+
"N805", # First argument of a method should be named `self`
164+
"N806", # Variable in function should be lowercase
103165
]
166+
flake8-quotes = { inline-quotes = "double", multiline-quotes = "double" }
104167

105168
[tool.ruff.lint.isort]
106169
force-sort-within-sections = true

0 commit comments

Comments
 (0)