You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from nonebot.adapters.discord import on_slash_command
from nonebot.adapters.discord.api import StringOption
test = on_slash_command(name="test", description="test",
options=[StringOption(name="1", description="1")] + [])
Pylance报错:
Argument of type "list[StringOption]" cannot be assigned to parameter "options" of type "List[AnyCommandOption] | None" in function "on_slash_command"
Type "list[StringOption]" is incompatible with type "List[AnyCommandOption] | None"
"list[StringOption]" is incompatible with "List[AnyCommandOption]"
Type parameter "_T@list" is invariant, but "StringOption" is not the same as "AnyCommandOption"
Consider switching from "list" to "Sequence" which is covariant
"list[StringOption]" is incompatible with "None"
mypy报错:
Argument "options" to "on_slash_command" has incompatible type "list[StringOption]"; expected "list[SubCommandGroupOption | SubCommandOption | IntegerOption | StringOption | UserOption | ChannelOption | RoleOption | MentionableOption | NumberOption | BooleanOption | AttachmentOption] | None"Mypy[arg-type](https://mypy.readthedocs.io/en/latest/_refs.html#code-arg-type)
"List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
Consider using "Sequence" instead, which is covariant
The text was updated successfully, but these errors were encountered:
在使用on_slash_command新建斜杠指令时,为options提供动态的列表,会因为list不是covariant的而报错,即使是仅仅将两个静态列表相加也会报错。
MWE:
Pylance报错:
mypy报错:
The text was updated successfully, but these errors were encountered: