【问题标题】:Autocompletion for types that can be dynamically anything - not working可以是动态任何类型的自动完成 - 不起作用
【发布时间】:2019-07-26 19:13:47
【问题描述】:

我已经安装了 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

【问题讨论】:

    标签: python visual-studio-code intellisense


    【解决方案1】:

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

    IDE的原因并没有告诉你它有什么方法或数据字段是因为:

    1. 如果类型不能在编译时(或“执行前”)派生,IDE 不知道它是什么。

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

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

    顺便提一下,IDE第一次加载项目时需要索引文件的原因是因为它需要解析源代码并获取类型信息。

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2012-11-02
      • 1970-01-01
      相关资源
      最近更新 更多