可以是动态任何类型的自动完成 - 不起作用

Autocompletion for types that can be dynamically anything - not working

我安装了 PythonIntelliSense 扩展程序,可以自动完成 Python

我安装了包 matplotlib 并且完成了这个

import matplotlib.pyplot as plt

fig = plt. #figure() shows in completion menu

但是当我尝试这个时

fig = plt.figure()

fig. # no completion menu. Specifically looking for suptitle()

[编辑] 似乎这实际上与 Python 是动态的有关。例如,提示类型使其完成

fig = plt.figure()
assert isinstance(fig, figure.Figure)
fig. # now completes perfectly

通常,自动完成高度依赖于类型信息。

之所以IDE没有告诉你它有什么方法或数据字段是因为:

  1. 如果类型不能在编译时派生(或"before execution"),IDE不知道它是什么。

  2. 实际上IDE如果扫描所有可能的路径就可以自动补全,但这没有意义,性能会很差。

python 3.5之后,我们可以指定方法return类型。如果matplotlib添加类型提示,IDE可以支持自动补全

对了,IDE项目第一次加载时需要索引文件的原因是需要解析源代码和获取类型信息。