War*_* P 5 ide type-inference code-completion python-2.7 python-3.x
我已经测试了各种Python IDE的代码完成功能.是否存在可以在以下情况下执行代码完成的代码:
def foo(x):
print x.read() // remove this line, and type in "print x."
def main():
n = open("c:\\python27\\test.py");
foo(n)
Run Code Online (Sandbox Code Playgroud)
IDE必须弄清楚foo是在当前模块的某个地方调用的,参数是一个调用open()的返回值,它必须假定它是一个调用file.open,因此返回一个文件对象.因此,x.Ctrl + Space后面会调用代码完成并显示x作为文件对象,可以支持任何文件对象方法,包括read().
我发现PyScripter可以做到这一点:
n = open("c:\\python27\\test.py");
n. // hit <ctrl+space> after n.
Run Code Online (Sandbox Code Playgroud)
上面的代码完成方案是有效的,因为PyScripter做了一些特殊的代码完成逻辑来确定n是一个文件对象,但是似乎没有办法从静态分析中推断出可以推导出类型的对象类型或可用方法参数.
其次,如果Python 2.x中没有这样的东西,在Python 3.x中,现在有静态类型提示,是否有任何IDE支持它们?
def foo(x:'file'):
print x.read() // remove this line, and type in "print x." and hit ctrl+space
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1456 次 |
| 最近记录: |