我正在学习Python,我使用Vs code作为我的IDE,我有一些非常奇怪和烦人的错误。
当我导入模块时
import telegram
我收到错误
"telegram" is not accessed Pylance invalid syntaxMypysyntax (module) telegram
在我的文件上,这非常烦人。我已经写了 import telegram #type:ignore
以使错误消失。
当我也写的时候
async def hello(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="Hello, my name is MAS.")
我在
chat_id=update.effective_chat.id
上收到此错误
Item "None" of "Optional[Chat]" has no attribute "id"Mypyunion-attr
Item "None" of "Optional[Chat]" has no attribute "id"Mypyunion-attr
Item "None" of "Optional[Chat]" has no attribute "id"Mypyunion-attr
Item "None" of "Optional[Chat]" has no attribute "id"Mypyunion-attr
Item "None" of "Optional[Chat]" has no attribute "id"Mypyunion-attr
(property) effective_chat: Chat | None
.
即使出现这些错误,我也可以完美运行文件,没有任何问题,但我不明白为什么 vscode 会出现问题。它影响了我的生产力。我必须添加
#type:ignore
才能消除这些错误。
我有这些正在运行的扩展。
我搜索了所有谷歌和堆栈溢出,但没有找到任何可以解决我的问题的方法。我在
Vscode 市场上遇到了
mypy-type-checker.args
。
我相信它可以解决我的问题,但没有关于如何设置参数的文档。 vscode 市场上什么都没有。
对于初学者来说,mypy的文档甚至没有什么意义。