Skip to main content
 首页 » 编程设计

python之在 pydev 中为几个参数键入提示

2025年05月04日12zhwl

所以我需要在 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' 

有什么建议吗?或者有可能吗?

请您参考如下方法:

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

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.;