简体   繁体   English

pycharm自动补全提示变量

[英]Pycharm autocompletion hints for variables

I Pycharm I can hint the IDE for the variable type in a method like this: 我Pycharm我可以用这样的方法来提示IDE为变量类型:

def __init__(self, filepath=None):
    """
    Init a new instance
    :param str filepath: optional full path to file
    """

I'm trying to do the same for a single variable (could be a variable inside a module or a class), so the IDE will know what type of data should be stored in that variable 我正在尝试对单个变量(可以是模块或类中的变量)执行相同的操作,因此IDE将知道应在该变量中存储什么类型的数据

current_credentials = None
""":type CredentialsClass the current credentials class"""

but it doesn't help the IDE.. 但这对IDE没有帮助。

how can I do it properly ? 我该怎么做呢?

The syntax is slightly different here. 这里的语法略有不同。

On PyCharm 3.4.1 (as for me) the feature works well for the following example code: 在PyCharm 3.4.1(就我而言)上,该功能适用​​于以下示例代码:

x = None
""" :type x: str """

class C:
    """ :type v: str """
    v = None

How it looks like. 看起来如何。

Also, if you use your own types, and type definition is placed outside the current file, don't forget to import it or provide a scoped name. 另外,如果您使用自己的类型,并且类型定义位于当前文件之外,请不要忘记导入它或提供作用域名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM