使用 pydev 时,我可以用类型名注释参数以提供上下文信息吗?
我最近开始使用 pydev。看起来很棒。但有一个烦恼来自于 Python 是一种动态语言这一事实。当 pydev 知道类型时,许多自动完成功能都会起作用,所以
f = open("foo.txt")
效果很好,pydev 可以找出 f 是一个文件,并给我很好的建议。
但是,当处理我自己的函数中的参数时,pydev 显然无法确定类型信息:
def bar(x,y): #Pydev obv. cant tell exactly what x and y are
所以当我执行 x.
时,我显然没有得到任何建议。
如果能提供某种注释,让 pydev 可以选择来添加建议,并通过警告我应该这样做来帮助我编码更安全,那就太好了。我知道我的思考方式就像来自静态语言的人一样,但很多时候,参数的类型应该始终是一件事,而且只有一件事。我可以注释我的代码来帮助 pydev 吗?
I've recently started using pydev. It seems great. One annoyance though comes from the fact that python is a dynamic language. Many of the autocompletion features will work when pydev knows the type, so
f = open("foo.txt")
works great, pydev can figure out that f is a file and gives me great suggestions.
However, when dealing with parameters in my own functions, pydev obviously can't determine type information:
def bar(x,y): #Pydev obv. cant tell exactly what x and y are
So I obviously don't get any suggestions when I do x.
.
It would be great to provide some kind of annotation that pydev can pick up to add suggestions and also to help me code a little safer by warning me I should. I know I'm thinking like someone coming from a static language, but much of the time the type of an argument should always be one thing and only one thing. Can I annotate my code to help pydev out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 x 是一个列表,那么这应该有效:
If x is a list, then this should work:
您可以使用:
You may use: