【问题标题】:Type hinting in pydev for several parameters在 pydev 中为几个参数输入提示
【发布时间】:2014-05-06 17:54:36
【问题描述】:

所以我需要在 pydev 中进行一些类型提示并找到了这个:http://pydev.org/manual_adv_type_hints.html

class MyClass:

def method(self, a):
    ':type a: ClassA'

这是一种魅力。

但是,如果我有这样的事情: 我的班级:

def method(self, a, b):
    ':type a: ClassA'

如何获得两个参数的类型提示? 我尝试了各种组合

':type a,b: ClassA, ClassB

':type a, ClassA'
':type b, ClassB'

':type a, ClassA, b, ClassB'

有什么建议吗?还是有可能?

【问题讨论】:

    标签: python python-2.7 pydev type-hinting


    【解决方案1】:

    我注意到它适用于这种格式:

    class MyClass:
    
        def method(self, a, b):
            #: :type a: ClassA
            #: :type b: ClassB
    

    如果你问我,它也更具可读性。我只是将 Python 作为一种爱好才做了大约一周,所以不要相信我的话。

    这种格式的好处是它几乎适用于所有类型提示(PyDev 手册中的示例):

    class MyClass:
    
        def method(self, lst):
            #Can be on the same line
            for a in lst: #: :type a: GUITest
                a.;
    

    class MyClass:
    
        def method(self, lst):
            #Or on the line before
            #: :type a: GUITest
            for a in lst:
                a.;
    

    【讨论】:

    • 不错!谢谢。完美运行!
    猜你喜欢
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2011-08-03
    • 2020-04-28
    相关资源
    最近更新 更多