Skip to content

Commit 7432509

Browse files
authored
feat: 更新类型注解以适配 pyright 变更 (#164)
microsoft/pyright#10277
1 parent e975761 commit 7432509

File tree

13 files changed

+1770
-2213
lines changed

13 files changed

+1770
-2213
lines changed

alicebot/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from contextlib import AsyncExitStack
1515
from itertools import chain
1616
from pathlib import Path
17-
from typing import Any, Callable, Optional, Union, overload
17+
from typing import Any, Callable, Optional, Union, cast, overload
1818

1919
import anyio
2020
import structlog
@@ -366,7 +366,7 @@ def update_config(
366366
try:
367367
default_value = config_class()
368368
except ValidationError:
369-
default_value = ...
369+
default_value = cast("Any", ...)
370370
config_update_dict[config_class.__config_name__] = (
371371
config_class,
372372
default_value,

alicebot/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class BotConfig(ConfigModel):
5353
"""
5454

5555
event_queue_size: int = Field(default=0, ge=0)
56-
plugins: set[str] = Field(default_factory=set)
57-
plugin_dirs: set[DirectoryPath] = Field(default_factory=set)
58-
adapters: set[str] = Field(default_factory=set)
56+
plugins: set[str] = Field(default_factory=set[str])
57+
plugin_dirs: set[DirectoryPath] = Field(default_factory=set[DirectoryPath])
58+
adapters: set[str] = Field(default_factory=set[str])
5959
log: Optional[LogConfig] = None
6060

6161

alicebot/dependencies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ async def solve_dependencies(
109109
raise TypeError("can not solve dependent")
110110
sub_dependent.dependency = dependent_ann
111111
values[name] = await solve_dependencies(
112-
cast(Dependency[_T], sub_dependent.dependency),
112+
cast("Dependency[_T]", sub_dependent.dependency),
113113
use_cache=sub_dependent.use_cache,
114114
stack=stack,
115115
dependency_cache=dependency_cache,
116116
)
117117
depend_obj = cast(
118-
Union[_T, AbstractAsyncContextManager[_T], AbstractContextManager[_T]],
118+
"Union[_T, AbstractAsyncContextManager[_T], AbstractContextManager[_T]]",
119119
dependent.__new__(dependent), # type: ignore
120120
)
121121
for key, value in values.items():
@@ -124,22 +124,22 @@ async def solve_dependencies(
124124

125125
if isinstance(depend_obj, AbstractAsyncContextManager):
126126
depend = await stack.enter_async_context(
127-
cast(AbstractAsyncContextManager[_T], depend_obj)
127+
cast("AbstractAsyncContextManager[_T]", depend_obj)
128128
)
129129
elif isinstance(depend_obj, AbstractContextManager):
130130
depend = await stack.enter_async_context(
131-
sync_ctx_manager_wrapper(cast(AbstractContextManager[_T], depend_obj))
131+
sync_ctx_manager_wrapper(cast("AbstractContextManager[_T]", depend_obj))
132132
)
133133
else:
134134
depend = depend_obj
135135
elif inspect.isasyncgenfunction(dependent):
136136
# type of dependent is Callable[[], AsyncGenerator[T, None]]
137137
cm = asynccontextmanager(dependent)()
138-
depend = cast(_T, await stack.enter_async_context(cm))
138+
depend = cast("_T", await stack.enter_async_context(cm))
139139
elif inspect.isgeneratorfunction(dependent):
140140
# type of dependent is Callable[[], Generator[T, None, None]]
141141
cm = sync_ctx_manager_wrapper(contextmanager(dependent)())
142-
depend = cast(_T, await stack.enter_async_context(cm))
142+
depend = cast("_T", await stack.enter_async_context(cm))
143143
else:
144144
raise TypeError("dependent is not a class or generator function")
145145

alicebot/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class MessageSegment(ABC, BaseModel, Mapping[str, Any], Generic[MessageT]):
328328
"""
329329

330330
type: str
331-
data: dict[str, Any] = Field(default_factory=dict)
331+
data: dict[str, Any] = Field(default_factory=dict[str, Any])
332332

333333
@classmethod
334334
@abstractmethod

alicebot/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init_subclass__(
9191
if inspect.isclass(origin_class) and issubclass(origin_class, Plugin):
9292
try:
9393
_event_t, state_t, config_t = cast(
94-
tuple[EventT, StateT, ConfigT], get_args(orig_base)
94+
"tuple[EventT, StateT, ConfigT]", get_args(orig_base)
9595
)
9696
except ValueError: # pragma: no cover
9797
continue

alicebot/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_classes_from_module(module: ModuleType, super_class: _TypeT) -> list[_Ty
115115
and ABC not in module_attr.__bases__
116116
and not inspect.isabstract(module_attr)
117117
):
118-
classes.append(cast(_TypeT, module_attr))
118+
classes.append(cast("_TypeT", module_attr))
119119
return classes
120120

121121

@@ -244,7 +244,7 @@ def wrap_get_func(
244244
if func is None:
245245
func = sync_func_wrapper(lambda _: True)
246246
elif not inspect.iscoroutinefunction(func):
247-
func = sync_func_wrapper(cast(Callable[[EventT], bool], func))
247+
func = sync_func_wrapper(cast("Callable[[EventT], bool]", func))
248248

249249
async def _func(event: EventT) -> bool:
250250
return (

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@
2626
},
2727
"dependencies": {
2828
"@iconify-json/mdi": "^1.2.3",
29-
"unocss": "^65.4.3",
29+
"unocss": "^66.0.0",
3030
"vitepress": "^1.6.3",
3131
"vue": "^3.5.13"
3232
},
3333
"devDependencies": {
34-
"@eslint/js": "^9.19.0",
35-
"@types/node": "^22.13.1",
36-
"@unocss/eslint-config": "^65.4.3",
34+
"@eslint/js": "^9.25.0",
35+
"@types/node": "^22.14.1",
36+
"@unocss/eslint-config": "^66.0.0",
3737
"conventional-changelog-cli": "^5.0.0",
38-
"eslint": "^9.19.0",
39-
"eslint-config-prettier": "^10.0.1",
40-
"eslint-plugin-vue": "^9.32.0",
41-
"globals": "^15.14.0",
38+
"eslint": "^9.25.0",
39+
"eslint-config-prettier": "^10.1.2",
40+
"eslint-plugin-vue": "^10.0.0",
41+
"globals": "^16.0.0",
4242
"markdownlint-cli2": "^0.17.2",
43-
"prettier": "^3.4.2",
44-
"pyright": "^1.1.393",
45-
"typescript-eslint": "^8.23.0",
43+
"prettier": "^3.5.3",
44+
"pyright": "^1.1.399",
45+
"typescript-eslint": "^8.30.1",
46+
"vue-eslint-parser": "^10.1.3",
4647
"zhlint": "^0.8.2"
4748
},
4849
"pnpm": {

packages/alicebot-adapter-apscheduler/alicebot/adapter/apscheduler/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class Config(ConfigModel):
1717
"""
1818

1919
__config_name__ = "apscheduler"
20-
scheduler_config: dict[str, Any] = Field(default_factory=dict)
20+
scheduler_config: dict[str, Any] = Field(default_factory=dict[str, Any])

packages/alicebot-adapter-telegram/codegen.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class MethodDescription(BaseModel):
151151
name: str
152152
href: str
153153
description: Optional[list[str]] = None
154-
returns: list[str] = Field(default_factory=list)
155-
fields: list[FieldDescription] = Field(default_factory=list)
154+
returns: list[str] = Field(default_factory=list[str])
155+
fields: list[FieldDescription] = Field(default_factory=list[FieldDescription])
156156

157157
def to_api_method(self) -> str:
158158
"""生成 API 方法字符串。"""
@@ -225,9 +225,9 @@ class TypeDescription(BaseModel):
225225
name: str
226226
href: str
227227
description: Optional[list[str]] = None
228-
fields: list[FieldDescription] = Field(default_factory=list)
229-
subtypes: list[str] = Field(default_factory=list)
230-
subtype_of: list[str] = Field(default_factory=list)
228+
fields: list[FieldDescription] = Field(default_factory=list[FieldDescription])
229+
subtypes: list[str] = Field(default_factory=list[str])
230+
subtype_of: list[str] = Field(default_factory=list[str])
231231

232232
def to_model(self) -> str:
233233
"""生成模型代码。"""

0 commit comments

Comments
 (0)