问题描述
我正在使用文档字符串注释Python代码。注意,这只是一个例子,
def credit_bonus(self,num_purchases: int,total_spend: float)->int:
'''
Calculates eligible and additional credit bonus for a customer,compared to prevIoUs
yearly spends,and number of prevIoUs purchases.
Additional credit ranking of 2,if current number of purchases > prevIoUs purchaces,and current spend >= 95% prevIoUs spend.
Return: customer's credit ranking
'''
....
return credit_rank
在VSCode中显示该功能的注释时,将其悬停在另一个模块中的该函数上时,将不显示大于号。我已经尝试过各种转义字符>
,但到目前为止没有任何效果。
是否可以用Python文档字符串支付?
此外,我知道这不是表演的障碍,也不是强制性的,只是一个小小的方便,最终将导致键入,而不是大于。
njc,谢谢!
解决方法
为函数/方法 DocStrings 工作,而不是为类工作。自发布以来,我仍在 DocStrings 中键入 ,并且我注意到它(现在?)在哪里起作用,哪里不起作用。首先是一些规格;
- Windows 10 专业版 x64 20H2
- Visual Studio Code x64 1.52.1
- 适用于 Visual Studio Code 的 Microsoft Python 扩展 2020.12.424452561
我确实为函数或方法工作,
def __new_connection(self)->sqlite3.Connection:
'''
__new_connection(self)`->`sqlite3.Connection:\n
create a new connection using a connection string,time out,and isolation level settings.\n
return:
sqlite3.Connection.
'''
return sqlite3.connect(database=self.__con_str,timeout=self.__timeout,isolation_level=None,uri=True)
在 >
周围键入尖引号或反引号,或者在本例中为 ->
,将显示 符号,当为方法描述显示 DocString 时。
但是
对于类文档字符串,它不起作用。
class Broker:
'''
class wrapper for sqlite3 database objects and operations.\n
transaction type: auto-commit.\n
database type: file system database. not in-memory (:memory:)
isolation level is set to None,i.e. auto-commit,cache is private.
methods:\n
__new_connection(self)->sqlite3.Connection
creates a new sqlite3 connection object
__cursor_execute(self,conn: sqlite3.Connection,sqlCmd: str,params: tuple=())->sqlite3.Cursor
creates a cursor object,execute a parameterised sql statement
'''
不管在 周围放置什么符号或标记都不起作用。
如果我找到了 DocStrings 类的解决方法,我会再次发帖,假设它不起作用(仍然),如果我这样做了。
谢谢和问候, 新泽西