diff options
author | 2021-05-31 12:56:33 -0400 | |
---|---|---|
committer | 2021-05-31 12:56:33 -0400 | |
commit | 8591a21130e7f428acb7a2834702a058de4c0fa1 (patch) | |
tree | 901e14451214b897623ad01c65b65713656994b2 | |
parent | Re-introduced static method for role change exception handling. (diff) | |
parent | Merge pull request #1606 from Numerlor/doc-force-prefix-priority (diff) |
Merge branch 'main' of https://github.com/python-discord/bot into swfarnsworth/one_help_channel
-rw-r--r-- | bot/exts/info/doc/_cog.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 2a8016fb8..c54a3ee1c 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -27,11 +27,12 @@ log = logging.getLogger(__name__) # symbols with a group contained here will get the group prefixed on duplicates FORCE_PREFIX_GROUPS = ( - "2to3fixer", - "token", + "term", "label", + "token", + "doc", "pdbcommand", - "term", + "2to3fixer", ) NOT_FOUND_DELETE_DELAY = RedirectOutput.delete_delay # Delay to wait before trying to reach a rescheduled inventory again, in minutes @@ -181,22 +182,26 @@ class DocCog(commands.Cog): else: return new_name - # Certain groups are added as prefixes to disambiguate the symbols. - if group_name in FORCE_PREFIX_GROUPS: - return rename(group_name) - - # The existing symbol with which the current symbol conflicts should have a group prefix. - # It currently doesn't have the group prefix because it's only added once there's a conflict. - elif item.group in FORCE_PREFIX_GROUPS: - return rename(item.group, rename_extant=True) + # When there's a conflict, and the package names of the items differ, use the package name as a prefix. + if package_name != item.package: + if package_name in PRIORITY_PACKAGES: + return rename(item.package, rename_extant=True) + else: + return rename(package_name) - elif package_name in PRIORITY_PACKAGES: - return rename(item.package, rename_extant=True) + # If the symbol's group is a non-priority group from FORCE_PREFIX_GROUPS, + # add it as a prefix to disambiguate the symbols. + elif group_name in FORCE_PREFIX_GROUPS: + if item.group in FORCE_PREFIX_GROUPS: + needs_moving = FORCE_PREFIX_GROUPS.index(group_name) < FORCE_PREFIX_GROUPS.index(item.group) + else: + needs_moving = False + return rename(item.group if needs_moving else group_name, rename_extant=needs_moving) - # If we can't specially handle the symbol through its group or package, - # fall back to prepending its package name to the front. + # If the above conditions didn't pass, either the existing symbol has its group in FORCE_PREFIX_GROUPS, + # or deciding which item to rename would be arbitrary, so we rename the existing symbol. else: - return rename(package_name) + return rename(item.group, rename_extant=True) async def refresh_inventories(self) -> None: """Refresh internal documentation inventories.""" |