Skip to content

Use raw strings for docstrings with forward slashes#816

Merged
ikuyarihS merged 2 commits into
masterfrom
extensions-cog-docstring-deprecation-warning
Mar 4, 2020
Merged

Use raw strings for docstrings with forward slashes#816
ikuyarihS merged 2 commits into
masterfrom
extensions-cog-docstring-deprecation-warning

Conversation

@SebastiaanZ
Copy link
Copy Markdown
Contributor

A few docstrings in bot.cogs.extensions use forward slashed to escape Markdown rendering when the docstrings are used in our bot's help feature. However, forward slashes are also interpreted as escape sequences in Python and since these ones are not valid, they will now raise a DeprecationWarning:

/home/sebastiaan/pydis/repositories/bot/bot/cogs/extensions.py:72: DeprecationWarning: invalid escape sequence \*

PEP 257 -- Docstring Conventions specifies that you should use raw strings whenever a docstring contains forward slashes:

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""".

So that's what I did; I turned those docstrings into raw strings.


Note: The DeprecationWarning will only show up when the code is compiled to bytecode (i.e., when the compiler is involved). Once the module is compiled to bytecode and saved as a .pyc, the warning will no longer show up until you clean __pycache__ and/or make changes to the file forcing it to be recompiled.

A few docstrings in `bot.cogs.extensions` have forward slashed in them to escape Markdown rendering when our help feature uses these docstring in a Discord message. However, the use of forward slashes with an invalid escape sequence in docstrings now raises a DeprecationWarning in Python:

/home/sebastiaan/pydis/repositories/bot/bot/cogs/extensions.py:72: DeprecationWarning: invalid escape sequence \*

PEP 257 (Docstring Conventions, https://www.python.org/dev/peps/pep-0257/) states that raw strings should be used for docstrings that use forward slashes, so I've added the `r`-prefix to the docstrings that use forward slashes.
@SebastiaanZ SebastiaanZ added t: bug Something isn't working p: 3 - low Low Priority status: needs review labels Mar 4, 2020
@SebastiaanZ SebastiaanZ requested a review from a team as a code owner March 4, 2020 07:55
@SebastiaanZ SebastiaanZ requested review from ikuyarihS and sco1 and removed request for a team March 4, 2020 07:55
@ikuyarihS ikuyarihS merged commit 1d8e441 into master Mar 4, 2020
@ikuyarihS ikuyarihS deleted the extensions-cog-docstring-deprecation-warning branch March 4, 2020 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: 3 - low Low Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants