VSCode Python 自动补全仅不适用于某些类
当在我的 python 项目中使用 VSCode 的自动完成功能时,除了一个类之外,它运行得很好,我不明白为什么。
该类来自模块 database
,该模块总共包含 3 个类:DatabaseClient
、Database
、Collection
DatabaseClient
有一个 get_database()
方法,该方法返回一个 Database
对象。Database
有一个 get_collection()
方法,它返回一个 Collection
对象。Collection
有多种方法。
自动完成功能按 DatabaseClient
& 上的预期工作。 Database
对象,但根本不在 Collection
对象上。
下面的代码可以工作并给出预期结果(屏幕截图结果的第 15 行和第 20 行匹配),但在编辑时不会自动完成,如上所述。
import lib.database as database
print( database.DatabaseClient().get_database('business').get_collection('reviews').find() )
client = database.DatabaseClient()
db = client.get_database(client.list_database_names()[0])
coll = db.get_collection(db.list_collection_names()[0])
print(coll.find())
尝试重新加载 VSCode,卸载并重新加载 python 扩展。
尝试卸载并重新安装 python 扩展。
尝试更改我的模块的名称。
尝试更改班级名称。
尝试更改 Collection
类的方法名称。
尝试使用单行命令行 3 并发现它是这样工作的。
When using autocompletion in VSCode in my python project, it works very well except for one class and I cannot figure out why.
The class is coming from a module database
which contains 3 classes total: DatabaseClient
, Database
, Collection
DatabaseClient
has a get_database()
method which returns a Database
object.Database
has a get_collection()
method which returns a Collection
object.Collection
has several methods.
The autocompletion works as intended on the DatabaseClient
& Database
objects, but not at all on the Collection
object.
The code below works and give the expected results (line 15 and 20 of the screenshot results match), but not the autocompletion while editing as stated above.
import lib.database as database
print( database.DatabaseClient().get_database('business').get_collection('reviews').find() )
client = database.DatabaseClient()
db = client.get_database(client.list_database_names()[0])
coll = db.get_collection(db.list_collection_names()[0])
print(coll.find())
Tried to reload VSCode, unload and reload the python extensions.
Tried to uninstall and re-install the python extensions.
Tried to change the name of my module.
Tried to change the name of the class.
Tried to change the name of the method of the Collection
class.
Tried using single line command line 3 and noticed it worked this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了解决方案。
问题来自于不使用方法头中的类型。
一旦我添加了正确的输入,自动完成功能就可以按预期在任何地方工作。
Found out the solution.
The problem comes from not using typing in the method headers.
Once I added proper typing, the autocompletion worked everywhere as expected.