如何使PyCharm在方法中自动完成代码? [英] How to get PyCharm to auto-complete code in methods?

查看:97
本文介绍了如何使PyCharm在方法中自动完成代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用第三方时l 诸如 boto 之类的库,PyCharm似乎能够很好地自动完成

When I'm using a 3rd party l ibrary such as boto, PyCharm seems to be able to auto-complete quite nicely

但是,一旦我定义了自己的功能,该功能内部就会自动完成.我理解为什么,因为我无法向函数提供有关其参数的任何类型信息,所以它无法猜测如何自动完成.有没有解决这个问题的方法?

However, as soon as I define a function of my own, auto-complete breaks down inside that function. I understand why, since I can't give the function any type information about its arguments, so it can't guess how to auto-complete. Is there a way around this issue?

修改

我尝试使用docstring(适用于Python 2),但仍无法自动完成

I tried using the docstring (for Python 2), but still no auto-complete

def delete_oldest_backups(conn, backups_to_keep, backup_description):
    """
    delete_oldest_backups(EC2Connection, int, string)
    """

(也尝试了boto.ec2.connection.EC2Connection而不只是EC2Connection)

推荐答案

您可以使用类型提示:

You can use type hints: http://www.jetbrains.com/pycharm/webhelp/type-hinting-in-pycharm.html

 def some_method(self, conn):
   """
   @type conn: EC2Connection
   """
   conn.<autocomplete>

这篇关于如何使PyCharm在方法中自动完成代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆