简体   繁体   English

Python 文档字符串注释,大于和小于符号未显示

[英]Python Docstring Comments, Greater Than and Less Than Symbols Not Showing

I'm commenting Python code using docstrings.我正在使用文档字符串注释 Python 代码。 Note, this is just an example,注意,这只是一个例子,

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

When the comment is displayed for this function, in VSCode, when hovering over this function in another module it is called from, the greater than symbol is not displayed.当显示此函数的注释时,在 VSCode 中,将鼠标悬停在调用它的另一个模块中的此函数上时,不显示大于号。 I have tried various escape characters, >我尝试了各种转义字符, > , so far nothing works. ,到目前为止没有任何效果。

Is it possible to dispay, < and >, in Python docstrings?是否可以在 Python 文档字符串中显示 < 和 >?

Also, I know this is not a show stopper, nor imperative, just a minor convenience, will end up typing, greater than, instead.另外,我知道这不是表演障碍,也不是命令式,只是一个小小的方便,最终会打字,大于,而不是。

Thanks and regards, njc谢谢和问候,新泽西州

Working for function / method DocStrings, not for Class.为函数/方法 DocStrings 工作,而不是为类工作。 Since posting, I'm still typing < and > in DocStrings, and I have noticed where it (now?) works, and where it doesn't.自发布以来,我仍在 DocStrings 中键入 < 和 >,并且我注意到它(现在?)在哪里起作用,哪里不起作用。 First some specs;首先是一些规格;

  • Windows 10 Pro x64 20H2 Windows 10 专业版 x64 20H2
  • Visual Studio Code x64 1.52.1 Visual Studio Code x64 1.52.1
  • Microsoft Python extension for Visual Studio Code 2020.12.424452561适用于 Visual Studio Code 的 Microsoft Python 扩展 2020.12.424452561

I does work for functions or methods,我确实为函数或方法工作,

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)

Typing the, acute or back quote, around the > , or in this case -> , will display < and > symbols, when the DocString is displayed for the method's description.>或在本例中->周围键入尖引号或反引号,将显示 < 和 > 符号,当 DocString 显示为方法描述时。

But

For class docstrings, it doesn't work.对于类文档字符串,它不起作用。

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
    '''

Doesn't work, no matter what symbol, or mark up, are placed around the < or >.无论在 < 或 > 周围放置什么符号或标记,都不起作用。

I shall post again if I find a work around for class DocStrings, assuming it doesn't work (still), if I do.如果我找到 DocStrings 类的解决方法,我将再次发布,假设它不起作用(仍然),如果我这样做了。

Thanks and regards, njc谢谢和问候,新泽西州

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM