如何记录函数返回tuple
的方式,以便PyCharm能够将其用于类型提示?
受挫的例子:
def fetch_abbrev_customer_info(customer_id):
"""Pulls abbreviated customer data from the database for the Customer
with the specified PK value.
:type customer_id:int The ID of the Customer record to fetch.
:rtype:???
"""
... magic happens here ...
return customer_obj.fullname, customer_obj.status #, etc.
答案 0 :(得分:44)
我联系了PyCharm的支持,这就是他们所说的:
对于元组,请使用
(<type_1>, <type_2>, <type_3>, e t.c.)
语法。E.g:
""" :rtype: (string, int, int) """
这已在PyCharm's documentation中确认:
类型语法
Python文档字符串中的类型语法未由任何标准定义。因此,PyCharm建议采用以下符号:
...
- (Foo,Bar)#Foo和Bar的Tuple