我想知道处理与其他模块相关的未知类型的函数/方法的最佳方法是什么。请注意,我正在使用strict
模式
例如,我有以下内容:
rooms: List[str] = list(mongo_client.devices.distinct("room"))
mongo_client
MongoClient
只是从导入的一个实例pymongo
。VSCode 尖叫它不知道distinct
方法的类型:
Type of "distinct" is partially unknown
Type of "distinct" is "(key: Unknown, filter: Unknown = None, session: Unknown = None, **kwargs: Unknown) -> Unknown"PylancereportUnknownMemberType
Argument type is unknown
Argument corresponds to parameter "iterable" in function "__init__"PylancereportUnknownArgumentType
我可以做什么:
- 添加
reportUnknownMemberType
到pyrightconfig.json
; 但是,虽然这会删除之前的警告,但它也会禁用我可能真正想要的警告 - 加上
# type: ignore
那个独特的电话;我通常讨厌有这样的无视评论,我认为它不会“修复”任何事情 - 自己创建一个存根文件
你会怎么做?我不应该使用strict
模式吗?大多数项目都是在激活严格模式的情况下编写的,以确保我没有遗漏任何东西。这些是cast
我能做的吗?
谢谢!