类成员的Pydev数据类型提示

时间:2014-03-18 01:13:59

标签: python comments intellisense pydev

根据pydev手册,可以使用注释为变量提供类型提示 http://pydev.org/manual_adv_type_hints.html

我正在尝试通知pydev有关类成员的类型(以便代码完成和智能感知可以正常工作)。

以下是我的尝试:

class a:
    def __init__(self):
        self.a=None
        self.b=None

    def setVariable(self,a,b)
        self.a=a
        self.b=b

    def doSomething(self):
        ': :type self.a: packageX.moduleY.ClassZ'
        # use self.a from here on

但它似乎不起作用。任何人都能解释一下吗?

1 个答案:

答案 0 :(得分:2)

似乎Pydev(3.4.1)不支持类属性的docstring-type-hinting,以及类型提示变量向类属性的传播。

这是我期望工作的一个例子: (鉴于此类,我希望在示例代码的最后两行中提供完成建议,原因在这些行的注释中提到的原因。)

class SampleClass(object):
    """Summary of class here.

    Attributes:
        member: Member
        @type member: MemberClass
        other_member: Another member
    """

    def __init__(self, other=None):
        """Inits SampleClass with blah.

        Args:
            @param other: Instance of OtherMemberClass
            @type other: OtherMemberClass
        """
        self.other_member = other
        self.member = None

    def public_method(self):
        """Performs operation blah."""
        self.member.#should get completions from MemberClass here because hinted in class docstring
        self.other_member.#should get completions from OtherMemberClass here because `other` was assigned to attribute in __init__, and `other` type was hinted in __init__ docstring.

我在Pydev跟踪器上opened a ticket重新编写此内容。