I'm commenting Python code using docstrings. 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. I have tried various escape characters, >
, so far nothing works.
Is it possible to dispay, < and >, in Python docstrings?
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. Since posting, I'm still typing < and > in DocStrings, and I have noticed where it (now?) works, and where it doesn't. First some specs;
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.
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.
Thanks and regards, njc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.