Skip to content

The documentation command doesn't handle backticks if there is trailing text #3284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
algmyr opened this issue Mar 1, 2025 · 4 comments
Open
Labels
a: information Related to information commands: (doc, help, information, reddit, site, tags) good first issue Good for newcomers l: 0 - beginner p: 2 - normal Normal Priority status: approved The issue has received a core developer's approval t: bug Something isn't working

Comments

@algmyr
Copy link

algmyr commented Mar 1, 2025

E.g. the command

!d `collections.Counter` some more text

does not work. It does work without the trailing text. Probably this is a nice simple first issue if someone wants to pick it up.

@algmyr
Copy link
Author

algmyr commented Mar 1, 2025

So probable culprit:

The code that tried to handle backticks is here:
https://github.com/python-discord/bot/blob/main/bot/exts/info/doc/_cog.py#L337

But the splitting of the string happens way later in:
https://github.com/python-discord/bot/blob/main/bot/exts/info/doc/_cog.py#L236

It's likely these should happen together, either moving the split much earlier, or the backtick handling much later.

@wookie184 wookie184 added t: bug Something isn't working good first issue Good for newcomers p: 2 - normal Normal Priority a: information Related to information commands: (doc, help, information, reddit, site, tags) l: 0 - beginner status: approved The issue has received a core developer's approval labels Mar 1, 2025
@anand2312
Copy link
Member

anand2312 commented Mar 11, 2025

Just changing the .strip("`") on L337 (first link in the above comment) to a .replace("`", "") ought to fix this

@vivekashok1221
Copy link
Member

vivekashok1221 commented Mar 11, 2025

Since we only support searching for a single symbol, we could simply ignore the text that comes after the first argument by changing the method's signature:

diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py
index 105f0510..c0020ce7 100644
--- a/bot/exts/info/doc/_cog.py
+++ b/bot/exts/info/doc/_cog.py
@@ -302,12 +302,12 @@ class DocCog(commands.Cog):
             return embed
 
     @commands.group(name="docs", aliases=("doc", "d"), invoke_without_command=True)
-    async def docs_group(self, ctx: commands.Context, *, symbol_name: str | None) -> None:
+    async def docs_group(self, ctx: commands.Context, symbol_name: str | None = None) -> None:
         """Look up documentation for Python symbols."""
         await self.get_command(ctx, symbol_name=symbol_name)
 
     @docs_group.command(name="getdoc", aliases=("g",))
-    async def get_command(self, ctx: commands.Context, *, symbol_name: str | None) -> None:
+    async def get_command(self, ctx: commands.Context, symbol_name: str | None = None) -> None:
         """
         Return a documentation embed for a given symbol.
 
(END)

(i.e, changing symbol_name from a keyword-only parameter (which acts as a catch-all in dpy) to a single optional parameter)

@vivekashok1221
Copy link
Member

Since we only support searching for a single symbol,

I wrote this comment with this assumption in mind. I realize now that invocations like !docs not in are allowed (thanks to #1014) to retrieve reference docs for not in . If we change the method signature like I suggested, !docs not in will instead show results for the not operator. To specifically get results for not in, you would need to run !docs "not in".

I think the best solution, as algmyr said, would be to handle backticks much later- probably in get_symbol_item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: information Related to information commands: (doc, help, information, reddit, site, tags) good first issue Good for newcomers l: 0 - beginner p: 2 - normal Normal Priority status: approved The issue has received a core developer's approval t: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants